Thursday, 2 July 2015

OAF: How to add logging / debug messages in Oracle Application Framework

In this post I will explain how to write log / debug statements in Controller (CO), Application Module Implementation class(AM), ViewObject and ViewObject Row Implementation class (VO) and Entity Object Implementation class (EO) in OA Framework.

OA Framework has a method writeDiagnostics() which can be used from anywhere in the above mentioned classes. This methods are published by oracle.apps.fnd.framework.webui.OAPageContext and oracle.apps.fnd.framework.server.OADBTransaction (for example, if you want to make logging calls in a UI controller, use OAPageContext. If you want to make logging calls from an application module, use OADBTransaction).  Below give are the example to show how to call these methods in different places.



To view log mesages, select the Diagnostics global button from any page (this global button is configured as part of the standard global menu added to each page; the display of this menu item is controlled by the profile option FND: Diagnostics (FND_DIAGNOSTICS)) 

Diagnostics can be enabled at various levels:
  • Show Log - directs you to the Oracle Applications Manager where you can view a "snapshot" of your Oracle E-Business Suite system.
  • Show Log on Screen - allows you to specify a log level and display Java log messages for a particular HTTP Request-Response at the end of the current page. For additional information about this feature, refer to the section titled "Using Logging to Screen" in the Oracle Application Framework Developer's Guide chapter called How to Configure Logging of the Oracle E-Business Suite Supportability Guide, available on the Applications Release 12 Online Documentation CD.
  • Set Trace Level - displays the Set Trace page where you can specify the level of information to collect in a database trace. 
  • Show Pool Monitor - displays the Application Pool Monitor where you view different aspects of runtime and configuration information about the JVM.
Here we are discussing only about the option "Show Log on Screen".

The debug messages can be written in various level:

  • Statement (1)
  • Procedure(2)
  • Event(3)
  • Exception (4)
  • Error (5)
  • Unexpected(6)
Depends on which options you choose, the screen will display all the debug messges written on that level or above. I prefer to write the debug messages at the exception level, so if I select the option Exception(4) in the screen, i can see only my debug messages.(most of the standard logging statements are written at Statement(1) level.)
  • From a Controller
 if(pageContext.isLoggingEnabled(OAFwkConstants.EXCEPTION))  
 {  
      pageContext.writeDiagnostics(this,"[TestCO]processRequest():- <Log Message Here!!!!!!>",OAFwkConstants.EXCEPTION);  
 }  
  • From AM Impl class
 if(this.isLoggingEnabled(OAFwkConstants.EXCEPTION))   
 {  
      this.writeDiagnostics(this,"[TestAMImpl]testMethod():- <Log Message Here!!!!!!>",OAFwkConstants.EXCEPTION);  
 }  
  • From VOImpl class
 if(this.isLoggingEnabled(OAFwkConstants.EXCEPTION))   
 {  
      this.writeDiagnostics(this,"[TestVOImpl]testMethod():- <Log Message Here!!!!!!>",OAFwkConstants.EXCEPTION);  
 }  
  • From VORow Impl class
 import oracle.apps.fnd.framework.server.OAApplicationModuleImpl;  
 OAApplicationModuleImpl appModule = (OAApplicationModuleImpl)this.getApplicationModule();  
 if(appModule.isLoggingEnabled(OAFwkConstants.EXCEPTION))   
 {  
      appModule.writeDiagnostics(this,"[TestVORowImpl]testMethod():- <Log Message Here!!!!!!>",OAFwkConstants.EXCEPTION);  
 }  
  • From EOImpl class
 import oracle.apps.fnd.framework.server.OADBTransaction;  
 OADBTransaction transaction = this.getOADBTransaction();  
 if(transaction.isLoggingEnabled(OAFwkConstants.EXCEPTION))   
 {  
      transaction.writeDiagnostics(this,"[TestEOImpl]testMethod():- <Log Message Here!!!!!!>",OAFwkConstants.EXCEPTION);  
 }  
If you are running from Jdeveloper, you could just use the SOP statements.
 System.out.println("[TestCO]processRequest():- <Error Message Here!!!!!!>");  

This is a custom method which I normally use, which is helpful when you want to change the debug levels. This is used in CO, if you want you can write something similar in AM :)
 public void writeLog(OAPageContext pageContext, String message)   
 {  
      if(pageContext.isLoggingEnabled(OAFwkConstants.EXCEPTION))  
      {  
           pageContext.writeDiagnostics(this,message,OAFwkConstants.EXCEPTION);  
      }  
      System.out.println(message);  
 }  


Related Links: Logging in OAF Pages – A Technical Note!



Feel free to point out if anything is missing/wrong in this blog.

No comments:

Post a Comment