'How to exclude a particular package from Log4j appender?
I have a simple unique appender for all packages of my application. I need to remove some particular sub-package logs from the main file and add it to another separated file, how can I do?
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="console-log" target="SYSTEM_OUT" >
<PatternLayout pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n" />
</Console>
<RollingFile name="file-log" fileName="app.log" filePattern="app.%i.log">
<PatternLayout>
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n</pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="10MB" />
</Policies>
<DefaultRolloverStrategy max="5"/>
</RollingFile>
<RollingFile name="weblink-log" fileName="weblink.log" filePattern="weblink.%i.log">
<PatternLayout>
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n</pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="10MB" />
</Policies>
<DefaultRolloverStrategy max="5"/>
</RollingFile>
</Appenders>
<Loggers>
<Root level="warn">
<AppenderRef ref="console-log" />
<AppenderRef ref="file-log" />
</Root>
<Logger name="com.myapp" level="debug"/>
<Logger name="com.myapp.weblink" level="debug" additivity="false">
<AppenderRef ref="console-log" />
<AppenderRef ref="weblink-log" />
</Logger>
</Loggers>
</Configuration>
With this configuration com.myapp.weblink logs are logged into weblink-log AND file-log appenders, how can I divide them?
I want all logs but "weblink" packange into file-log and just "weblink" logs into weblink-log.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
