Skip to end of metadata
Go to start of metadata

Default Configuration with Pax Logging

Newcomers often wonder why Pax Exam produces either too much or too little log output or why a change in the logging configuration does not have the expected effect.

To understand logging in Pax Exam, keep in mind that logging needs to be configured separately for the test driver and the test container, which may even run in separate processes.

Pax Exam uses the SLF4J logging API, which requires a static binding to a logging backend to produce any output at all.

By default, Pax Exam provisions Pax Logging to the test container. Pax Logging provides both an org.slf4j package and an org.slf4j.impl binding implemented by log4j. There is currently no way to use an alternative binding with Pax Logging.

For the driver, you can also use Pax Logging as a plain old JAR, or use the official slf4j-api JAR together with a binding of your choice. Note that this will not affect logging inside the test container.

Overriding Pax Logging with SLF4J and Logback

If you prefer SLF4J and Logback to Pax Logging and log4j, you can override the defaults of Pax Exam as follows:

Pax Exam >= 2.4.0

  • Set the configuration property pax.exam.system = default to disable all standard options normally set by Pax Exam - this includes the provisioning option for Pax Logging.
  • Include provisioning options for SLF4J and logback and all remaining standard options of Pax Exam in the @Configuration method of your test class.
  • You can factor out these options to a static method producing a composite option which can be reused in other test classes.

Pax Exam <= 2.3.0

For older Pax Exam releases, there is a slightly hackish but effective way of replacing Pax Logging:

  • Create a file META-INF/links/ in the classpath of your project containing this line:

By doing so, you fool Pax Exam into provisioning SLF4J instead of Pax Logging.

  • Add the following options to your tests:

This takes care of logging inside the test container.

  • Add the following dependencies to your POM

This takes care of logging outside the test container. The last one is only required for the Pax Runner Container.

  • No labels