Pax Coin - Provider - File System - Example

As an example lets see how you can use this provider to configure Pax Logging. Pax Logging can be configured via Configuration Admin via a Managed Service with pid "org.ops4j.pax.logging". The configuration properties are the same as the ones used to configure log4j.
Lets say that we want to configure Pax Logging that in certain circumstances to use an INFO log level and sometimes to use DEBUG. To do this you can:

  • somewhere on your file system create a file named org.ops4j.pax.logging.properties
    The content of org.ops4j.pax.logging.properties could be:
    log4j.rootLogger=INFO, CONSOLE
    log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
    log4j.appender.CONSOLE.layout=org.apache.log4j.TTCCLayout
    

To use this configuration you can start your preferred OSGi framework, provisioning Pax Coin bundles, Pax Coin File System Configuration Provider and your bundles that perform logging (that this feel hard? Then you missed Pax Runner). You should also configure File System Configuration Provider to point to the directory containing the properties file from above.
Once everything is up and running, do something that triggers logging. You should see now only INFO messages. Then edit the file above and change INFO to DEBUG, save the file and do again that something that triggered logging. You should see now also DEBUG messages.

Can you see how useful it can be in an production environment? You can go by default with a logging configuration for ERROR and as soon as there is a problem and you want to trace edit logging configuration to DEBUG. You are done? Rollback to ERROR by editing the file.