I have a log4j appender defined like:
log4j.logger.com.example = DEBUG, filelog
log4j.appender.filelog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.filelog.File=c:/app.log
log4j.appender.filelog.layout=org.apache.log4j.PatternLayout
log4j.appender.filelog.layout.ConversionPattern=%d | %m%n
log4j.appender.filelog.DatePattern=.dd-MM-yyyy
In my class, I get the logger like:
Log logger = LogFactory.getLog(getClass());
This works properly. I want to have a logger that always logs certain messages (not errors, but things like how long transactions took). If I write these at DEBUG or INFO, I won't see them if the log level is changed. I think I can accomplish this using another appender that writes to the same file.
Is this possible to have two appenders write to the same file? How would I get the logger instance where I want to use the normal debug appender and the transactional appender in the same class? These messages won't all be in the same package, so I can't configure a certain package to always log. Will I have to have these appenders write to different files, or can I retrieve them both in the code and have something like:
Log alwaysLogger = LogFactory.getLog(ALWAYS);
alwaysLogger.debug("This message will always be written regardless of the level set on the filelog appender");
Update I could write to two different log files if necessary, but how would I get the logger instance in my class? I don't want to configure one package/class to always use one appender over the other as the classes will have to log information/error messages and the transactional "always" messages during a normal run. Is there a way to accomplish what I need even if it write to two different log files?