I want my app to have 4 log files. Three of the log files are the typical log4j Info, Warn and Error logs. The 4th log file is completely unrelated and is used to log 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 "Hello" text is correctly written to the info.log file. But the data.log file is never created or written to.
Why is the DATA_LOG.info("Some data") line not writing to the data.log file, and what code change do I need to make in order for that to happen?
commons
should work as well, can you try thisinstead of this
Update Just tested this code works:
log4j.properties
Test Code
Output
Are you missing something?