Using Log4j in Oracle ADF application

As i talked about more of ADF logger in my previous Adf logger post.Now what if you want log4j in ADF application.

1) Add the log4j JAR file to the project library JAR file .

2) Then you need to create log4j.properties file in your application src directory.

Content of properties file-

#####################################################

# Set root logger level to INFO and its only appender to ConsoleOut.
log4j.rootLogger=INFO,ConsoleOut,F

# ConsoleOut is set to be a ConsoleAppender.
log4j.appender.ConsoleOut=org.apache.log4j.ConsoleAppender

# ConsoleOut uses PatternLayout.
log4j.appender.ConsoleOut.layout=org.apache.log4j.PatternLayout
log4j.appender.ConsoleOut.layout.ConversionPattern=%-5p: [%d] %c{1} – %m%n

#####################################################

now you can use log4j as below –

package com.techartifact.log4jSample;

import org.apache.log4j.Logger;
import org.apache.log4j.Category;
import org.apache.log4j.PropertyConfigurator;
import javax.servlet.*;
import javax.servlet.http.*;



public class Log4JSample
extends HttpServlet
{
Logger log = Logger.getLogger(this.getClass().getSimpleName());
private static final String CONTENT_TYPE = "text/html; charset=windows-1252";

public void init(ServletConfig config)
 throws ServletException
{
 super.init(config);
 log.info("inside init() method of Log4JSample");
}

public void doGet(HttpServletRequest request,
                 HttpServletResponse response)
 throws ServletException, IOException
{
 log.info("inside doGet method of Log4JSample");
}
}

Happing logging in Techartifact with Vinay Kumar. 🙂

Vinay

I am an Oracle ACE in Oracle ADF/Webcenter. Sr Java Consultant-working on Java/J2EE/Oracle ADF/Webcenter Portal/ content and Hibernate for several years. I'm an active member of the OTN JDeveloper/Webcenter forum. Passionate about learning new technologies. I am here to share my knowledge. Give your views and suggestion on [email protected] .

More Posts - Website

Follow Me:
TwitterLinkedInGoogle PlusYouTube