Integrating the Monolog framework in Jonathan

1. Instrumentation code

Each Jonathan implementation package has a LoggerProvider class, which provides the other classes of the same package with static loggers :

There are two ways to instrument Jonathan source code :

2. Using the default configuration

The default configuration is established thanks to the Kilim configuration files (kcf files). In the runtime kcf (monolog.kcf), package loggers are mapped to the default topical logger hierarchy.

The default mapping is following :

3. Modifying the runtime kcf

3.1. Loggers

In the configuration /loggers, a topical logger is defined by his name (his initial topic), his associated level and a set of handlers. These parameters may be modified by users. However, modifying a logger name, adding a new logger or deleting a logger will change the logger hierarchy.

[loggers]
   [root]
      ...
      [org]
         ...
         [objectweb]
            ...
            [jonathan]
               => {/factories/monolog factory,.}
               name => (String.class, jonathan)
               parent => /loggers/root/org/objectweb
               level => /levels/WARN
               additivity => (boolean, false)
               [handlers]
                  0 -> /handlers/file
               [binding]
                  ...
                  [export]
                     ...
                  [bind]
                     ...
               [communication]
                  ...
                  [send]
                     ...
                  [receive]
                     ...

3.2. Mapping of package loggers

The loggers of a package are mapped to the logger hierarchy in the configuration /packages. Users may modify the mapping of the loggers used in a package. The following example describes the mapping of the loggers of the package org.objectweb.jonathan.protocols.tcpip :

[packages]
   ...
      [tcpip]
         generic logger -> /loggers/root/org/objectweb/jonathan/communication
         bind logger    -> /loggers/root/org/objectweb/jonathan/binding/bind
         export logger  -> /loggers/root/org/objectweb/jonathan/binding/export
         send logger    -> /loggers/root/org/objectweb/jonathan/communication/send
         receive logger -> /loggers/root/org/objectweb/jonathan/communication/receive
      ...

3.3. Handlers

There are three default handlers defined in the configuration /handlers : file handler, rolling file handler and console handler. In the following example, it is possible to specify a new pattern on the file handler or to change the log file name.

[handlers]
   [file]
      => {/factories/monolog factory,.}
      name => (String.class, FileHandler)
      output => (String.class, jonathan_logs.txt)
      pattern => (String.class, %l - %O.%M : %m%n)
      type => (String.class, File)
   [file]
      => {/factories/monolog factory,.}
      name => (String.class, RollingFileHandler)
      output => (String.class, jonathan_logs.txt)
      pattern => (String.class, %l - %O.%M : %m%n)
      type => (String.class, RollingFile)
   [console]
      => {/factories/monolog factory,.}
      name => (String.class, ConsoleHandler)
      output => (String.class, System.err)
      pattern => (String.class, %l - %m%n)
      type => (String.class, Console)

4. Using a Monolog property file

In accordance with the Monolog specification, it is possible to use a property file for a specific configuration. User properties in the monolog.properties file will overwrite the default parameters defined in the runtime kcf.

However, users can not modify the default logger hierarchy and mapping by editing the property file.

# file monolog.properties

# Logger factory class name
log.config.classname org.objectweb.util.monolog.wrapper.log4j.MonologLoggerFactory

########################
# Logger configuration #
########################

#logger.org.objectweb.jonathan.level WARN
#logger.org.objectweb.jonathan.additivity false
#logger.org.objectweb.jonathan.handler.0 FileHandler

#logger.org.objectweb.jonathan.binding.level WARN
#logger.org.objectweb.jonathan.binding.additivity false
#logger.org.objectweb.jonathan.binding.handler.0 FileHandler

#logger.org.objectweb.jonathan.binding.export.level WARN
#logger.org.objectweb.jonathan.binding.export.additivity false
#logger.org.objectweb.jonathan.binding.export.handler.0 FileHandler

#logger.org.objectweb.jonathan.binding.bind.level WARN
#logger.org.objectweb.jonathan.binding.bind.additivity false
#logger.org.objectweb.jonathan.binding.bind.handler.0 FileHandler

#logger.org.objectweb.jonathan.communication.level WARN
#logger.org.objectweb.jonathan.communication.additivity false
#logger.org.objectweb.jonathan.communication.handler.0 FileHandler

#logger.org.objectweb.jonathan.communication.send.level WARN
#logger.org.objectweb.jonathan.communication.send.additivity false
#logger.org.objectweb.jonathan.communication.send.handler.0 FileHandler

#logger.org.objectweb.jonathan.communication.receive.level WARN
#logger.org.objectweb.jonathan.communication.receive.additivity false
#logger.org.objectweb.jonathan.communication.receive.handler.0 FileHandler

5. References

  1. Sébastien Chassande-Barrioz, Monolog general documentation
  2. Sacha Krakowiak, Jonathan tutorial, Chapter 4 : The Configuration Framework