Friday, July 18, 2008

I love log4j

Logging is a very useful thing. Without this most of our java softwares are like black boxes.
The major problems we face is setting up the log4j. Also trying to decipher the cryptic clues is annoying, like say log4j WARNING No appenders could be found. Who has time to fix these issues..
Well it pays of well if you fix it as I said u cant fix a software problem without seeing what is happening inside. It will be like the movie HAPPENING(Should have been what is happening) ...


A few tricks to get the log4j setup:
Passing VM arguments
-Dlog4j.configuration=file:C:/development/projects/webapp/target/classes/log4j.properties

-Dlog4j.debug=true .....Excellent option to know what is happening inside log4j.


commonly used log4j.properties is below:
---------------------------------------------------------------------------------------------
log4j.rootLogger=debug, stdout, R

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=example.log

log4j.appender.R.MaxFileSize=100KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=1

log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
-----------------------------------------------------------------------------------------

More log  to come here...

Ref: http://logging.apache.org/log4j/1.2/manual.html

No comments: