Wednesday, March 24, 2010

LOG4J :D

How to redirect log messages to different appenders:
http://veerasundar.com/blog/2009/08/log4j-tutorial-how-to-send-log-messages-to-different-log-files/ :

http://groovy.dzone.com/news/groovy-and-log4j

Sample config:
logdir = /home/tapomay/logs

log4j.rootLogger=INFO, root

log4j.logger.DEFAULTLOGGER=DEBUG, root
log4j.appender.root=org.apache.log4j.DailyRollingFileAppender
log4j.appender.root.File=${logdir}/app.log
log4j.appender.root.DatePattern='.'yyyy-MM-dd-HH
log4j.appender.root.layout=org.apache.log4j.PatternLayout
log4j.appender.root.layout.ConversionPattern=<%d> %5p [%t](%C{1}) - %m%n

log4j.appender.LOGGER1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.LOGGER1.File=${logdir}/app.module1.log
log4j.appender.LOGGER1.DatePattern=yyyy-MM-dd-HH
log4j.appender.LOGGER1.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGGER1.layout.ConversionPattern=<%d> %5p [%t](%C{1}) - %m%n

log4j.appender.LOGGER2=org.apache.log4j.DailyRollingFileAppender
log4j.appender.LOGGER2.File=${logdir}/app.module2.log
log4j.appender.LOGGER2.DatePattern=yyyy-MM-dd-HH
log4j.appender.LOGGER2.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGGER2.layout.ConversionPattern=<%d> %5p [%t](%C{1}) - %m%n

log4j.appender.LOCK=org.apache.log4j.DailyRollingFileAppender
log4j.appender.LOCK.File=${logdir}/app.locks.log
log4j.appender.LOCK.DatePattern=yyyy-MM-dd-HH
log4j.appender.LOCK.layout=org.apache.log4j.PatternLayout
log4j.appender.LOCK.layout.ConversionPattern=<%d> %5p [%t](%C{1}) - %m%n


log4j.additivity.LOGGER1=false
log4j.additivity.LOGGER2=false
log4j.additivity.LOCK=false

log4j.logger.LOGGER1=INFO, LOGGER1
log4j.logger.LOGGER2=DEBUG, LOGGER2
log4j.logger.LOCK=INFO, LOCK

In JAVA:
public static Logger DEFAULT = Logger.getLogger("DEFAULTLOGGER");
public static Logger LOG1 = Logger.getLogger("LOGGER1");
public static Logger LOG2 = Logger.getLogger("LOGGER2");
public static Logger LOG_LOCK = Logger.getLogger("LOCK");

 

No comments:

Post a Comment