I'd like a very simple XML configuration file with a console and a file appender using log4j2.
(The Apache Website is killing me with much Information.)
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="Console"
target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
<File name ="MyFile"
fileName ="all.log"
immediateFlush ="false"
append ="false">
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</File>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Console"/>
<AppenderRef ref="MyFile"/>
</Root>
</Loggers>
</Configuration>
Notes:
log4j2.xml
log4j2.xml
file in a folder which is in the class-path (i.e. your source folder "src")Logger logger = LogManager.getLogger();
to initialize your loggerimmediateFlush="false"
since this is better for SSD lifetime. If you need the log right away in your log-file remove the parameter or set it to true