0
votes

My log4j.properties file is pasted below. My understanding is that we need to add Appenders to the root logger for the appender to work. As you can see in the below properties file, only appender A is attached to the root logger (log4j.rootLogger=info, A). However, what I see is that the logging information is printed to both the appenders (ConsoleAppender - A and File Appender - B). How is this possible?

log4j.rootLogger=info, A
log4j.appender.A=org.apache.log4j.ConsoleAppender
log4j.appender.A.layout=org.apache.log4j.PatternLayout
log4j.appender.A.layout.ConversionPattern=%-4r [%t] [rid=%X{RID} ] %-5p %c %x - %m%n

log4j.appender.B=org.apache.log4j.FileAppender
log4j.appender.B.layout=org.apache.log4j.PatternLayout
log4j.appender.B.file=target/server.log
log4j.appender.B.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
1

1 Answers

0
votes

Well, it turns out that the Console appender (A) was printing out to the server.log (glassfish log) which incidentally is also the name of the log file associated with appender B.

The following property was attached to the glassfish server (startup parameters) which helped me understand which log4j.properties (in case of stray properties file) file is loaded along with information like what appenders are used for logging.

-Dlog4j.debug=true