Its been a while since I blogged last.
Here, in this post I am going to explain about adding loggers in ADF.
It is good to have loggers implemented for any ADF application. It makes life easier for the developers and the support team to debug any errors once the code is moved to DEV, QA or PROD instances.
Generally, developers use ADF loggers. But, by default the ADF logger statements will be written to the default server log. As we know the server log has lots of other things also, it is difficult to separately analyze the logger statements.
So, most of them who have a requirement to write loggers to a specific file use log4j.
In this blog I am going to explain you a way to write ADF loggers to a specific file.
1. Create a log handler in the logging.xml file.
To configure log handler, open the logging.xml file. The logging.xml file will be present in the below location.
yourDefaultDomain\config\fmwconfig\servers\DefaultServer\logging.xml
You have to add the log handler like below.
3. In your application you have to define the logger like below. The name should be same as the logger name given in the logging.xml file.
ADFLogger logger = ADFLogger.createADFLogger("applicationLog");
4. After this, add log statements in your code where necessary. Usually at the start of the method, end of the method in try, catch blocks ... etc.
While you write log statements it is better to check logger level like below.
if (logger.isFine())
logger.info("Start of init() method.");
Say, after you move the code to production and you don't want to print the loggers, then you can change the server level to WARNING. So, FINE messages will not appear.
5. So, you can check your ADF logger file in the location
yourDefaultDomain\servers\DefaultServer\logs\yourApplication.log
Hope this post helps you all in configuring ADF loggers.
Here, in this post I am going to explain about adding loggers in ADF.
It is good to have loggers implemented for any ADF application. It makes life easier for the developers and the support team to debug any errors once the code is moved to DEV, QA or PROD instances.
Generally, developers use ADF loggers. But, by default the ADF logger statements will be written to the default server log. As we know the server log has lots of other things also, it is difficult to separately analyze the logger statements.
So, most of them who have a requirement to write loggers to a specific file use log4j.
In this blog I am going to explain you a way to write ADF loggers to a specific file.
1. Create a log handler in the logging.xml file.
To configure log handler, open the logging.xml file. The logging.xml file will be present in the below location.
yourDefaultDomain\config\fmwconfig\servers\DefaultServer\logging.xml
You have to add the log handler like below.
<log_handlers>
...
<log_handler name='applicationHandler' class='oracle.core.ojdl.logging.ODLHandlerFactory' filter='oracle.dfw.incident.IncidentDetectionLogFilter'>
<property name='path' value='${domain.home}/servers/${weblogic.Name}/logs/yourApplication.log'/>
<property name='maxFileSize' value='14979657'/>
<property name='maxLogSize' value='104857600'/>
<property name='rotationFrequency' value='daily'/>
<property name='retentionPeriod' value='week'/>
<property name='encoding' value='UTF-8'/>
<property name='useThreadName' value='true'/>
<property name='useSourceClassAndMethod' value='ERROR'/>
</log_handler>
...
</log_handlers>
2. Create a logger in the same file.
<loggers>
...
<logger name='applicationLog' level='FINEST' useParentHandlers='false'>
<handler name='applicationHandler'/>
</logger>
...
</loggers>
ADFLogger logger = ADFLogger.createADFLogger("applicationLog");
4. After this, add log statements in your code where necessary. Usually at the start of the method, end of the method in try, catch blocks ... etc.
While you write log statements it is better to check logger level like below.
if (logger.isFine())
logger.info("Start of init() method.");
Say, after you move the code to production and you don't want to print the loggers, then you can change the server level to WARNING. So, FINE messages will not appear.
5. So, you can check your ADF logger file in the location
yourDefaultDomain\servers\DefaultServer\logs\yourApplication.log
Hope this post helps you all in configuring ADF loggers.
Thanks for your post Nitish. It was helpful. I have a question.
ReplyDeleteis it possible to append the current date with the log file name?
Whenever a logger is added, weblogic by default prints timestamp along with it.
DeleteU need not add it again!
Thanks for your reply. I didn't quite explain it well. I need to add the current date with log file name like this "yourApplication.mm-dd-yyyy.log". How can I achieve this in ADF Logger? I know we can use DailyRollingFileAppender in log4j but not sure in ADF.
DeleteHi. useful, but I am getting a lot of info back, and that makes it impossible to read.
ReplyDeleteI wrote "Loglevel severe" to the log and this is the output:
[2015-07-22T15:47:21.813-04:00] [DefaultServer] [ERROR] [] [SSFapplicationLog] [tid: [ACTIVE].ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'] [userId: anonymous] [ecid: 40e0825b3ad4f379:-4ae73fb1:14eb74c5b3b:-8000-0000000000000028,0] [APP: ADFApp] [SRC_CLASS: com.ssf.view.beans.departments] [SRC_METHOD: tryAllLoggers] Loglevel severe