Configuring Pax Logging

This articles will (eventually) answer the following questions:

  1. How to change the logging level from the command line? Tried this with no effect:
    mvn pax:provision -Dorg.ops4j.pax.logging.DefaultServiceLog.level=INFO
    
  2. How to use a configuration admin service to configure Pax Logging?
  3. How to use Pax ConfMan to configure Pax Logging?

I haven't yet found out how to solve (1), and I haven't examined the config admin service in order to do (2), but I do seem to have a solution to (3):

  • Create folder myapp/runner/configurations/services
  • Add a file myapp/runner/configurations/services/org.ops4j.pax.logging.properties with contents:
    log4j.rootLogger=INFO, A1
    log4j.appender.A1=org.apache.log4j.ConsoleAppender
    log4j.appender.A1.layout=org.apache.log4j.PatternLayout
    
    # Print the date in ISO 8601 format
    log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
    
  • Add dependencies for Felix config admin service and Pax ConfMan:
    mvn pax:import-bundle -DgroupId=org.apache.felix -DartifactId=org.apache.felix.configadmin -Dversion=1.0.1
    mvn pax:import-bundle -DgroupId=org.ops4j.pax.confman -DartifactId=pax-confman-propsloader -Dversion=0.2.2
    
  • Run as usual:
    mvn clean install pax:provision
    

More details:

The documentation for Pax Logging states:

By default, there is a Root logger created in the Pax Logging Service, which is set to DEBUG level and a fairly extensive output format to the ConsoleAppender. This configuration may be suitable for the initial startup, and by using the Config Admin Service you can configure logging as you need. The configuration pid used by Pax Logging is org.ops4j.pax.logging.

The documentation for Pax ConfMan states:

paxconfman-propsloader will get the directory to load from system property bundles.configuration.location. This defaults to the CURRENT_DIR/configurations. The directory should contain two folders, services and factories, for service configurations and for factory configurations respectively. Each folder will contain .properties, named as the PID of the service you want to configure.

From this, we can deduce that we should place a file called org.ops4j.pax.logging.properties containing the log4j configuration keys in CURRENT_DIR/configurations/services. But what is CURRENT_DIR? After some research, I found that it is the runner folder.

Make sure that pax-logging and the two config bundles are loaded before bundles that emit lots of debugging statements.