Hi,
I am using log4j2 version 2.0.1.
I have configured 2 Loggers viz. root logger and another logger with
additivity as false and .
Now my application logs goes to root logger to Rolling File Appender which
works fine. But I want to separate out the event logs generated by my
application to a different file using Routing Appender to create a file for
each kind of event separately.
Problem is all the event logs are going to ROOT logger and not to the
separate logger, when I log using
EventLogger.logEvent(StructuredDataMessage) but If I use
logger.info(StructuredDataMessage) the Routing Appender create the log file
with the name ${sd:type} and not the desired files
How can, I route the event logs to a particular logger?
*Code to Write Logs*
==================
package com.stats.test;
public class TestStats {
private static Log logger = Log.getLogger(TestStats.class);
public static void logStats() {
StructuredDataMessage msg = new StructuredDataMessage("S_1",
"Stats Test
Msg", "S_1");
StructuredDataMessage msg2 = new StructuredDataMessage("S_2",
"Stats Test
Msg2", "S_2");
EventLogger.logEvent(msg, Level.INFO);
EventLogger.logEvent(msg2, Level.INFO);
logger.info(msg);
logger.info(msg2);
}
}
===================
*Config File*
===================
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="info" name="Log4jConfig" monitorInterval="600"
shutdownHook="disable" packages="">
<Appenders>
<RollingFile name="RollingFile" fileName="logs/application.log"
filePattern="logs/%d{yyyy-MM-dd}_%i.application.log.gz">
<ThresholdFilter level="info"/>
<PatternLayout>
<Pattern>%d{yyyy-MM-dd HH:mm:ss} [Thread-%t] %-5p %c %x [%M-%L] -
%m%n</Pattern>
</PatternLayout>
<Policies>
<OnStartupTriggeringPolicy/>
<TimeBasedTriggeringPolicy interval="1" modulate="false"/>
<SizeBasedTriggeringPolicy size="100 MB"/>
</Policies>
<DefaultRolloverStrategy min="1" max="20"/>
</RollingFile>
<Routing name="Routing">
<Routes pattern="$${sd:type}">
<Route>
<RollingFile name="Rolling-${sd:type}"
fileName="logs/stats/${sd:type}/${sd:type}_stats.log"
filePattern="logs/stats/${sd:type}/${sd:type}_stats_%d{yyyy-MM-dd-HH}_%i.log.gz">
<ThresholdFilter level="info"/>
<PatternLayout>
<pattern>%d{yyyy-MM-dd HH:mm:ss}|%m%n</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="3" modulate="false"/>
<SizeBasedTriggeringPolicy size="1 GB"/>
</Policies>
<DefaultRolloverStrategy min="1" max="20"/>
</RollingFile>
</Route>
</Routes>
</Routing>
</Appenders>
<Loggers>
<Logger name="com.stats.test" level="info" additivity="false">
<AppenderRef ref="Routing"/>
</Logger>
<Root level="trace">
<AppenderRef ref="RollingFile"/>
</Root>
</Loggers>
</Configuration>
===================
Regards,
Parkirat Singh Bagga.
--
View this message in context:
http://apache-logging.6191.n7.nabble.com/Separate-the-event-logs-generated-by-EventLogger-Logs-How-tp50112.html
Sent from the Log4j - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]