I have two loggers. One that appends to a file, and another that is an smtp logger. There is a class (MyClass below) that is logging error messages that I would like to log to the file appender ONLY. Can this be done?
I tried adding this with no luck.
log4j.logger.com.test.MyClass=OFF, email_logger
Here is my log4j.properties.
log4j.logger.com.test=INFO, file_logger, email_logger
log4j.logger.com.test.MyClass=OFF, email_logger
log4j.additivity.com.test=false
log4j.appender.file_logger=org.apache.log4j.RollingFileAppender
log4j.appender.file_logger.file=/path/to/file.log
log4j.appender.file_logger.MaxFileSize=5MB
log4j.appender.file_logger.threshold=INFO
log4j.appender.file_logger.MaxBackupIndex=5
log4j.appender.file_logger.layout=org.apache.log4j.PatternLayout
log4j.appender.file_logger.layout.ConversionPattern=%d [%t] %-5p %c{1} - %m%n
log4j.appender.email_logger=org.apache.log4j.net.SMTPAppender
log4j.appender.email_logger.threshold=ERROR
log4j.appender.email_logger.SMTPHost=mtahost
log4j.appender.email_logger.BufferSize=512
log4j.appender.email_logger.subject=System Error
log4j.appender.email_logger.from=test@test.com
log4j.appender.email_logger.to=someone@test.com
log4j.appender.email_logger.layout=org.apache.log4j.PatternLayout
log4j.appender.email_logger.layout.ConversionPattern=%d [%t] %-5p %c{1} - %m%n
I figured it out. I was thinking about it incorrectly. With the configuration above, I was actually turning off all logging on MyClass altogether. What I wanted to do was remove the email appender from MyClass and leave the file appender. I also needed to additivity to false on MyClass so that the same messages is not picked up by the base (log4j.logger.com.test) logger.
I removed this line:
And added these lines: