Thank you for visiting! If you liked the site, please add a bookmark, else add a critical comment! Would you like to visit Greece? Traditional Greek flag This real estate site is only available in Greek! The holy mountain

Thursday, 16 September 2010

JDeveloper 11g:Using Log4j in an ADF application module

This is another concise instance for using Log4j in  an ADF application module, that is  in a  model project. The steps are quite similar:
starting with adding the log4j library, as shown in the image on your left hand side.
Next,  you need to create a file, within:


just  like the following:

# Set root logger level to INFO and its only appender to ConsoleOut.
log4j.rootLogger=INFO, ConsoleOut
# ConsoleOut is set to be a ConsoleAppender.
# ConsoleOut uses PatternLayout.
log4j.appender.ConsoleOut.layout.ConversionPattern=%-5p: [%d] %c{1} - %m%n
#Addon for

Third, you need to edit your code just like that:


import org.apache.log4j.Logger;


public class TuhraServiceImpl extends TuhraApplicationModuleImpl implements TuhraService {

  private Logger logger = Logger.getLogger(this.getClass());


public void createNewImageForEmployee(Number employeeId, String imageName){

   if (logger.isDebugEnabled())
      logger.debug("New image has been created!");   



Finally,  you should see your logger message appear in the log output window;

INFO : [2010-09-16 10:26:16,517] TuhraServiceImpl - New image has been created!

Would you like to refactor?

Moreover, you could move the code line below:

private Logger logger = Logger.getLogger(this.getClass());

 to the super class:

package tuhra.model.framework;

import oracle.jbo.server.ApplicationModuleImpl;
import org.apache.log4j.Logger;

public class TuhraApplicationModuleImpl extends ApplicationModuleImpl {

  protected Logger logger = Logger.getLogger(this.getClass().getName());


Once more, your custom  logger message should appear in the log output :

INFO : [2010-09-16 15:20:02,247] TuhraServiceImpl - New image has been created!

Finally, if you need more tips about appenders:  

No comments:

Post a Comment