I'm new to log4j. I want to create a different file for each log level (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 looks 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 writes the error level in the file ripper_erro.log. The warn does not write to any file.
How do I have to record in ripper_warning.log the warn level events?