I want 4 log files in my application. Three of the log files are typical log4j Info, Warn, and Error logs. The 4th log file is completely unrelated and is used to record some data.
My log4j.properties file looks like this:
log4j.threshold=ALL
log4j.rootLogger=ALL, InfoAppender, WarnAppender, ErrorAppender
log4j.DATA_LOGGER=INFO, DataAppender
log4j.additivity.DATA_LOGGER = false
log4j.appender.DataAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.DataAppender.File=/app_logs/data.log
log4j.appender.InfoAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.InfoAppender.File=/app_logs/info.log
log4j.appender.WarnAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.WarnAppender.File=/app_logs/warn.log
log4j.appender.ErrorAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.ErrorAppender.File=/app_logs/error.log
And my Java code looks like this:
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
private static final Log LOG = LogFactory.getLog(SomeClassInMyApp.class);
private static final Log DATA_LOG = LogFactory.getLog("DATA_LOGGER");
private static void foo() {
LOG.info("Hello");
DATA_LOG.info("Some data");
}
When I run this, the text "Hello" is correctly written to the info.log file. But the data.log file is never created or written.
Why is the DATA_LOG.info line ("Some data") not written to the data.log file, and what code change needs to be done in order for this to happen?
source
share