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.)
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.)
log4j2 has a very flexible configuration system (which IMHO is more a distraction than a help), you can even use JSON. See https://logging.apache.org/log4j/2.x/manual/configuration.html for a reference.
Personally, I just recently started using log4j2, but I'm tending toward the "strict XML" configuration (that is, using attributes instead of element names), which can be schema-validated.
Here is my simple example using autoconfiguration and strict mode, using a "Property" for setting the filename:
Here is my simplistic
log4j2.xml
that prints to console and writes to a daily rolling file:Output:
A new log file will be created daily with previous day automatically renamed to:
cucumber_yyyy-MM-dd.log
In a Maven project, you would put the
log4j2.xml
insrc/main/resources
orsrc/test/resources
.Notes:
Logger logger = LogManager.getLogger();
to initialize your logger