Skip to content

mmprogrami/setup-log4j2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Set up log4j2

Just arranges dependencies to set up log4j2. Arranges logging from jul and slf4j (1 & 2) to log4j2.

Usage

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:

  1. It’ll transitively pull in necessary dependencies

  2. 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.

As a test dependency

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.

Override the root level

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 test

Or 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}&#x09;%highlight{%5.5p}&#x09;%c{1}&#x09;%m%n</log4j2.pattern>
     </systemPropertyVariables>
....

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages