Skip to end of metadata
Go to start of metadata

Author: Sheetal Gangele

As a user interface(UI) developer ,apart from regular coding and designing of UI some standard tasks also need to be taken care . For example some standards like globalization(Translatability),Accessibility(tab order etc.) also logging and tracing which is not only a standard but will help a developer and administrator to understand the control flow apart from comments . In this blog I will tell you not the general practice but some steps which will help you to find out the minimum places where logging and tracing needs to be done.

Firstly Some basics for logging tracing which is a prerequisite to know before starting.

Logs and traces are two manners of protocolling the events of your J2EE System. Logs are usually addressed to an administrator of a customer system. All significant events that occur on a cluster node of the J2EE Cluster are written to log files.Traces show the details of the control flow - they are watched by developers and the support organization. During normal operation developers and supporters are not looking on a running system. On the other hand the administrator has to check the system regularly.

a. Logging

  • records normal or exceptional events
  • switched on during normal operation
  • log messages are emitted to categories which describe distinguished problem areas such as database problems or security auditing
  • log messages are also visible in the trace

b. Tracing

  • reconstruction of the control flow of a running application
  • used during development or problem detection in productive systems (alternative to debugging)
  • trace messages are emitted to locations which describe delimited code areas such as packages or classes

The content of a message must be carefully designed with respect to the addressees and the message type (trace or log message) chosen.

  • Trace messages are intended for persons with development skills and a deep understanding of the application
  • log messages are intended for a much broader audience with different skills and backgrounds.

Points to keep in mind:-

  • An important part of any log and trace message is its severity. This denotes the level of importance or relevance of a certain message
  • The logging API provides these severities: DEBUG, PATH, INFO, WARNING, ERROR, FATAL
  • Categories and locations are associated with a severity. This acts as filter where only those messages that are of equal or higher severity may pass
  • Another important aspect of the logging API is destinations
  • This refers to where messages are actually written to (e.g. files, console, database)
  • Severity and destination make up the configuration of a location and category

To know more you can follow the links given at the end.

           In Web Dynpro framework a default tracer with the name logger is there always. So we can use it directly.For logging we have to define in begin others tab.

Private static final com.sap.tc.logging.Category realLogger =
          com.sap.tc.logging.Category.getCategory (Category. APPLICATIONS, "/<Location name >/<Application>");

Tracing: (Considering there is two different DC hierarchy for Model importing and other Dc will have just views.)

1. Find out all service calls and execute method in Model DC Comp Controller.

2. In UI DC Find out all the places (Actions,WDInit,Events,Methods,Private Classes etc) where try/catch block is there.

Logging:

1.Find out all catch blocks and there try to catch the exception in the logger  itself.

// This is in Model Controller

public void executeRequest_GetServiceCatagoryCatalogue( )
{
  //@@begin executeRequest_GetServiceCatagoryCatalogue()
  //$$begin Service Controller56(206883155)

  // This is used on entering of every method
  tracer.infoT(MODEL_UI_COMPCONTROLLER, ENTERING \+ EXECUTE_GET_SERVICE_CATEGORY);

  IWDMessageManager manager = wdComponentAPI.getMessageManager();
  try {
    // Reading of serviceIssueCategory from the properties file done in wdDoInit()
    wdContext.currentRequest_GetServiceCatagoryCatalogueElement().modelObject().execute();
    // debug is used on execute of every service to know that code has been executed till this point
    tracer.debugT(MODEL_UI_COMPCONTROLLER,  EXECUTE_GET_SERVICE_CATEGORY);
    wdContext.nodeResponse_ServiceCatalog().invalidate();
  } catch(Exception e) { // For logging and tracing of exception
    manager.reportException(e);
    tracer.catching(e);
    Logger.errorT(tracer, EXCEPTION + EXECUTE_GET_SERVICE_CATEGORY);
  } finally { // This is used on exiting of every method
    tracer.infoT(MODEL_UI_COMPCONTROLLER, EXITING \+  EXECUTE_GET_SERVICE_CATEGORY);
  }
  //$$end
  //@@end
}

//This is for UI Views on Action
public void onActionCheckUnit(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
  //@@beginonActionCheckUnit(ServerEvent)

  // This is used on entering of every method
  tracer.infoT(RECORD_REPAIR_CASE, ENTERING +CHECK_UNIT);
  wdThis.wdGetRecordRepairCaseCompController ().executeGetIndividualMaterialDetailByMaterialAndSerialID();
  // debug is used on execute of every service to know that code has been executed till this point
  tracer.debugT(RECORD_REPAIR_CASE, CHECK_UNIT);
  onActionSearchUnit(wdEvent);
  // debug is used on execute of every service to know that code has been executed till this point
  tracer.debugT(RECORD_REPAIR_CASE,CHECK_UNIT);
  wdThis.onActionFillMaterailBackEndData(wdEvent);
  // debug is used on execute of every service to know that code has been executed till this point
  tracer.debugT(RECORD_REPAIR_CASE,CHECK_UNIT);
  // This is used on exiting of every method
  tracer.infoT(RECORD_REPAIR_CASE, EXITING \+CHECK_UNIT);

  //@@end
}

I can't say that this is best practice to do,But these are the places where you need to follow logging/tracing.For refrences and to look into other methods in API you can read javadoc's link is provided

1.Quick Guide:

http://help.sap.com/saphelp_nw70/helpdata/en/a2/15ab41d60bcb46e10000000a155106/frameset.htm

2.Logging and tracing API in javadoc:

https://bis.wdf.sap.corp/twiki/bin/view/Techdev/JavaDoc

3.Logging Categories:

https://bis.wdf.sap.corp/twiki/bin/view/Techdev/JavaMonitoringAndManagementCategories