Why log4j.properties file :
I am using FileAppender
now, but if i would like to change my appender to JDBCAppender,
i have to open my java file and do the modifications and need to recompile. We can avoid this by writing
one .properties file.
By default the file name would be log4j.properties.
This properties file stores data in the form of key,
values pairs, in this file keys are fixed but values are our own (developer
changed).
log4j.properties
log4j.rootLogger=DEBUG, A1
log4j.appender.A1=org.apache.log4j.FileAppender
log4j.appender.A1.file=mylog.txt
log4j.appender.A1.file=mylog.txt
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern= %m %n
log4j.appender.A1.layout.ConversionPattern= %m %n
•
log4j.rootLogger
= DEBUG,A1 — > Here DEBUG means we are
specifying the level from where log4j methods execution must start, see mylog.txt file it showing all messages
right. But if we wrote log4j.rootLogger =
WARN,A1 then it will prints the messages in l.warn(), l.error(), l.fatal() only printed ,remaining logs ignore like l.debug(), l.info() because of priority.
•
I
have used FileAppender as my Appender, so if
we want to change my appender to ConsoleAppender,
i will open log4j.properties file and do the
modifications, so no need to touch our java classes, this is the main
advantage of log4j.properties file.
0 comments:
Post a Comment