Configure Log4j in simple steps
Hi All,
The logging framework always plays a crucial part in your application. In this post i will explain how to configure Log4J in simple steps.
Step1:
Put the Log4j jars file in classpath.
Step 2:
Create a log4j properties | xml file.
# Set root logger level to INFO
log4j.rootLogger=INFO,STDOUT
log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
log4j.appender.STDOUT.layout.ConversionPattern=%d %p [%t] %C{1} - %m\n
log4j.category.org.hibernate.SQL= STDOUT
log4j.category.org.hibernate.type= STDOUT
XML
<!--?xml version="1.0" encoding="UTF-8"?>
Step 3:
Write a program to load and start the logging in application
private static Logger logger = Logger.getLogger(TestJPAConfiguration.class);
public static void main(String[] args) {
//this is for basic loading
BasicConfigurator.configure();//Use property configurator to explicit load the log4j properties file.
//PropertyConfigurator.configure(“log4j.properties”);//in case of using XML config, Use DOM Configurator
// DOMConfigurator.configure(“log4j.xml”);logger.info(“Log4J Configured successfully”);
}
Hope this helps.
–
Thanks
R Vashi
Recent Comments