1
I am a log4j beginner. I want to create a different file for each level of log (warn, error and etc).
I have the following xml configuration file:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="error" strict="true" name="XMLConfigTest" packages="org.apache.logging.log4j">
<Properties>
<Property name="ErrorFileName">c:/ripper/ripper_error.log</Property>
<Property name="WarningFileName">c:/ripper/ripper_warning.log</Property>
</Properties>
<Appenders>
<Appender type="Console" name="STDOUT">
<Layout type="PatternLayout" pattern="%m MDC%X%n"/>
<Filters>
<Filter type="MarkerFilter" marker="FLOW" onMatch="DENY" onMismatch="NEUTRAL"/>
<Filter type="MarkerFilter" marker="EXCEPTION" onMatch="DENY" onMismatch="ACCEPT"/>
</Filters>
</Appender>
<Appender type="File" name="File" fileName="${ErrorFileName}">
<Layout type="PatternLayout">
<Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
</Layout>
</Appender>
<Appender type="File" name="FileWarning" fileName="${WarningFileName}">
<Layout type="PatternLayout">
<Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
</Layout>
</Appender>
</Appenders>
<Loggers>
<Logger name="warn" level="warn">
<AppenderRef ref="FileWarning" />
</Logger>
<Root>
<AppenderRef ref="File"/>
</Root>
</Loggers>
</Configuration>
In my class it’s like this:
public class HashMapFactory { final static Logger logger = LogManager.getLogger(HashMapFactory.class); //... logger.error("Erro! A chaveEL "+chaveEL+" está duplicada ou não há terminal cadastrado na TotalGirosLinhaEstacao."); logger.warn("teste"); }
It only saves the level error in the file ripper_error.log. warn it does not save to any file.
How do I have to write to ripper_warning.log the level warn events?