Friday, 12 September 2014

Log4j Example.

Create the class

import org.apache.log4j.Logger;

import java.io.*;
import java.sql.SQLException;
import java.util.*;

public class log4jExample{
  /* Get actual class name to be printed on */
  static Logger log = Logger.getLogger(
                      log4jExample.class.getName());

  public static void main(String[] args)
                throws IOException,SQLException{
 
     log.debug("Hello this is an debug message");
     log.info("Hello this is an info message");
  }
}

setting the lo4j.properties

log=/usr/home/log4j
log4j.rootLogger = DEBUG, FILE
# Define the file appender
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=${log}/log.out

# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%m%n

you can download the jar for log4j from below link

http://www.apache.org/dyn/closer.cgi/logging/log4j/1.2.17/log4j-1.2.17.zip
---------------------------------------------------------------------------------------

we  have another best log4j use in java porject please look in that..
it's real time use of log4j.

http://javadeveloperchoiceno1.blogspot.in/2014/11/how-to-use-log4jframework-in-our.html

-----------------------------------------------------------------------------------------

No comments:

Post a Comment