= log4j = Log4j is a fast and flexible framework for logging application debugging messages. * http://logging.apache.org/log4j/1.2/ * http://logging.apache.org/log4j/2.x/ # version 2 == Example log4j 1.2.17 == Project structure: {{{ . |-- log4j.properties |-- log4jexample.log |-- pom.xml |-- src | `-- main | `-- java | `-- org | `-- allowed | `-- bitarus | `-- log4jexample | `-- Main.java `-- target |-- classes | `-- org | `-- allowed | `-- bitarus | `-- log4jexample | `-- Main.class |-- log4jexample-1.0.0.0-SNAPSHOT.jar |-- maven-archiver | `-- pom.properties `-- surefire }}} === pom.xml === {{{#!highlight xml 4.0.0 org.allowed.bitarus log4jexample 1.0.0.0-SNAPSHOT jar log4jexample log4j log4j 1.2.17 }}} === Main.java === {{{#!highlight java package org.allowed.bitarus.log4jexample; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import org.apache.log4j.Logger; /* java -cp target/log4jexample-1.0.0.0-SNAPSHOT.jar:/home/vitor/.m2/repository/log4j/log4j/1.2.17/log4j-1.2.17.jar -Dlog4j.configuration="file:///home/vitor/Documents/log4jexample/log4j.properties" org.allowed.bitarus.log4jexample.Main */ public class Main{ public static void main(String[] args){ ExecutorService executorService = Executors.newFixedThreadPool(10); //org.allowed.bitarus.log4jexample.Main loggerName Logger logger = Logger.getLogger(Main.class); logger.info("test log4j info"); logger.debug("test log4j debug"); } } }}} === log4j.properties === {{{ log4j.logger.org.allowed.bitarus.log4jexample.Main=ALL,log4jexampleAppender,log4jexampleAppenderConsole log4j.appender.log4jexampleAppender=org.apache.log4j.DailyRollingFileAppender log4j.appender.log4jexampleAppender.File=log4jexample.log log4j.appender.log4jexampleAppender.layout=org.apache.log4j.PatternLayout log4j.appender.log4jexampleAppender.layout.ConversionPattern=%d{ISO8601}|%p|%c|%t|%m%n log4j.appender.log4jexampleAppender.Threshold=DEBUG log4j.appender.log4jexampleAppender.DatePattern='.'yyyyMMdd log4j.appender.log4jexampleAppenderConsole=org.apache.log4j.ConsoleAppender log4j.appender.log4jexampleAppenderConsole.layout=org.apache.log4j.PatternLayout log4j.appender.log4jexampleAppenderConsole.layout.ConversionPattern=%d{ISO8601}|%p|%c|%t|%m%n log4j.appender.log4jexampleAppenderConsole.Threshold=INFO }}} {{{ # Set root logger level to ALL and its only appender to appenderx. log4j.rootLogger=ALL, appenderx #log4j.appender.appenderx=org.apache.log4j.ConsoleAppender log4j.appender.appenderx=org.apache.log4j.RollingFileAppender log4j.appender.appenderx.File=/tmp/appXYZ.log # appenderx uses PatternLayout. log4j.appender.appenderx.layout=org.apache.log4j.PatternLayout log4j.appender.appenderx.layout.ConversionPattern=%d [%t] %-5p %c - %m%n }}}