Can we dsable log print for some customm creating Logger?
I have two loggers:
Root logger
Metrics Logger (which prints into file)
<Configuration status="WARN">
<Appenders>
<File name="file" fileName="app.log">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m %ex%n</Pattern>
</PatternLayout>
</File>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%d{yyyy-mm-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<logger name="metrics" level="info" additivity="true">
<AppenderRef ref="file"/>
</logger>
<root level="info">
<AppenderRef ref="STDOUT"/>
</root>
</Loggers>
</Configuration>
I want to disable print messages in console for File logger
The key to understanding is here http://logging.apache.org/log4j/2.x/manual/configuration.html#Additivity
The root logger is a parent of the logger "metrics". The log event of "metrics" is then passed to root logger's appender ("STDOUT"). This is known as additivity. It is possible to disable it by setting the additivity attribute on the logger "metrics" to false.
<logger name="metrics" level="info" additivity="false">
<AppenderRef ref="file"/>
</logger>