log4j experiments
2 loggers into 2 different files :
log = C:/Apache24/htdocs/logs
log4j.rootLogger=TRACE, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%24F:%t:%L] - %m%n
log4j.appender.debugLog=org.apache.log4j.FileAppender
log4j.appender.debugLog.File=${log}/debug.html
log4j.appender.debugLog.layout=org.apache.log4j.HTMLLayout
log4j.appender.debugLog.layout.Title=HTML Debug
log4j.appender.debugLog.layout.LocationInfo=true
log4j.appender.reportsLog=org.apache.log4j.FileAppender
log4j.appender.reportsLog.File=${log}/reports.html
log4j.appender.reportsLog.layout=org.apache.log4j.HTMLLayout
log4j.appender.debugLog.layout.Title=HTML Reports
log4j.appender.debugLog.layout.LocationInfo=true
log4j.category.debugLogger=TRACE, debugLog
log4j.additivity.debugLogger=false
log4j.category.reportsLogger=DEBUG, reportsLog
log4j.additivity.reportsLogger=false
And use this by:
static final Logger debugLog = Logger.getLogger("debugLogger");
static final Logger resultLog = Logger.getLogger("reportsLogger");
debugLog.debug("This is a debug level log entry in a debug log");
debugLog.info("This is an info level log entry in a debug log");
debugLog.warn("This is a warn level log entry in a debug log");
debugLog.error("This is an error level log entry in a debug log");
debugLog.fatal("This is a fatal level log entry in a debug log");
debugLog.trace("This is a trace level log entry in a debug log");
resultLog.debug("This is a debug level log entry in a result log");
resultLog.info("This is an info level log entry in a result log");
resultLog.warn("This is a warn level log entry in a result log");
resultLog.error("This is an error level log entry in a result log");
resultLog.fatal("This is a fatal level log entry in a result log");
resultLog.trace("This is a trace level log entry in a result log");
1 logger into 2 different files based on appender config:
log = C:/Apache24/htdocs/logs
log4j.rootLogger=TRACE, consoleApender, LogA, LogB
#Console Appender
log4j.appender.consoleApender=org.apache.log4j.ConsoleAppender
log4j.appender.consoleApender.Target=System.out
log4j.appender.consoleApender.layout=org.apache.log4j.PatternLayout
log4j.appender.consoleApender.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
#LogA Appender
log4j.appender.LogA=org.apache.log4j.FileAppender
log4j.appender.LogA.File=${log}/LogA.html
log4j.appender.LogA.layout=org.apache.log4j.HTMLLayout
log4j.appender.LogA.layout.LocationInfo=true
#LogB Appender
log4j.appender.LogB=org.apache.log4j.FileAppender
log4j.appender.LogB.File=${log}/LogB.html
log4j.appender.LogB.layout=org.apache.log4j.HTMLLayout
log4j.appender.LogB.layout.LocationInfo=true
# Set the logger level of File Appender to WARN
log4j.appender.LogA.Threshold = ERROR
log4j.appender.LogB.Threshold = debug
static final Logger rootLogger = Logger.getLogger(MISLoginController.class);
rootLogger.debug("This is a debug level log entry in a debug log");
rootLogger.info("This is an info level log entry in a debug log");
rootLogger.warn("This is a warn level log entry in a debug log");
rootLogger.error("This is an error level log entry in a debug log");
rootLogger.fatal("This is a fatal level log entry in a debug log");
rootLogger.trace("This is a trace level log entry in a debug log");
Comments
Post a Comment