I’m trying to figure out how to configure Log4J2 so that I can direct, say INFO and WARN level messages to the console, while directing ERROR level messages to a file. (For a stretch goal, I might want to direct DEBUG level messages to another file.) I’ve found some posts that gave variations of using ThresholdFilter
, but that didn’t seem to work. I couldn’t figure out what it was doing when I made a tweak to the config.
Does someone have a working solution that the average person can understand? The documentation is complex and difficult to understand. I’ve always had a hard time getting things to work from that source.
Below is the basic log4j2.xml that I use for basic log output. It works fine, except that everything goes to the console.
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout
pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %l - %msg%n" />
</Console>
</Appenders>
<Loggers>
<Root level="info" additivity="false">
<AppenderRef ref="console" />
</Root>
</Loggers>
</Configuration>