Just arranges dependencies to set up log4j2. Arranges logging from jul and slf4j (1 & 2) to log4j2.
Add the dependency to your project:
<dependency>
<groupId>nl.mmprogrami</groupId>
<artifactId>setup-log4j2</artifactId>
<version>1.3</version>
</dependency>This basically boils down to only two things:
-
It’ll transitively pull in necessary dependencies
-
will route JUL and SLF4J (1 & 2) to log4j2, so you can use those APIs and have the output end up in log4j2.
The only thing left to do is add a 'log4j2.xml' configuration file to your project, and you’re good to go.
This is possible too:
<dependency>
<groupId>nl.mmprogrami</groupId>
<artifactId>setup-log4j2</artifactId>
<version>1.1</version>
<classifier>test</classifier>
<scope>test</scope>
</dependency>This will accomplish the same things, but this jar also includes a default log4j2-test.xml configuration file, which will then be used when running tests. This is useful if you want to use logging in your test with minimal hassle in setting it up. You don’t even have to provide log4j2 configuration then. It will log INFO and above to the console.
You can any time place an overriding src/main/test/resources/log4j-test.xml anyway, but a few things can also be configured using system properties:
-
the root level (
log4j2.root.level) -
the pattern (
log4j2.pattern)
With a command line override
mvn -Dlog4j2.root.level=debug testOr like so, as configuration of the surefire plugin
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.5</version>
<configuration>
<systemPropertyVariables>
<log4j2.root.level>debug</log4j2.root.level>
<log4j2.pattern>%d{ISO8601}	%highlight{%5.5p}	%c{1}	%m%n</log4j2.pattern>
</systemPropertyVariables>
....