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
Pax Exam >= 2.4.0
- Set the configuration property
pax.exam.system = defaultto 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
@Configurationmethod 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.
- See Pax Exam's own RegressionConfiguration for a working example.
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/org.ops4j.pax.logging.api.linkin 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.