Subsections

2.2 Logging Support

The second ancillary component which is required by the reactor is a message logger. There are a number of Java logging frameworks available and the choice of the `best' logging framework will differ between applications. Therefore the logging functionality has been factored out of the reactor core, allowing different logging framework wrappers to be provided as part of the utility package.

The common logging interface is defined as shown in Listing 2.2. This acts as a factory which allows multiple logger objects to be created for different parts of the overall system. These factory methods are exposed via the public reactor API as shown in Listing 2.3.


\begin{listing}
% latex2html id marker 374\begin{small}\begin{verbatim}packa...
...\end{small}
\caption{Interface Definition for Reactor Log Target}
\end{listing}


\begin{listing}
% latex2html id marker 382\begin{small}\begin{verbatim}packa...
...ll}
\caption{Public Reactor API for Accessing Reactor Log Target}
\end{listing}

The public interface for each of the logger components is shown in Listing 2.4 and makes use of the logging level enumeration provided by the standard Java logging library. Logger objects will usually be created using unique identifiers that employ the conventional hierarchical naming system. This means that the core reactor functionality will be logged with the identification name of `com.zynaptic.reaction'.


\begin{listing}
% latex2html id marker 391\begin{small}\begin{verbatim}packa...
...{small}
\caption{Interface Definition for Reactor Logger Objects}
\end{listing}

The common logging interface is a fairly standard logging API, providing a set of defined log message severity levels and some methods for logging messages at one of these severity levels. This can easily be mapped onto existing logging frameworks using one of the wrappers described in the following subsections.

2.2.1 System Console Output

The simplest logging option involves printing all log messages to the console output. This can be useful during early development and is the default option used in the examples presented in this document. The system console log component is present in the utilities package as ReactorLogSystemOut.

2.2.2 Java Standard Logging Library

The most complete logging support is currently provided by a wrapper for the standard Java logging library (java.util.logging). This maps the members of the generic interface shown in Listing 2.4 onto the equivalent calls used by the conventional Java logger components. When used in this manner, the logging subsystem behaves in the same way as would be expected when directly accessing the standard Java logging library.

2.2.3 OSGi Logging Service

A wrapper around the OSGi log service API is included for situations where the Reaction framework is being run in an OSGi context. The wrapper is designed for use when the OSGi log service is declared as an optional import package for the Reaction bundle. This means that the OSGi logging package must be available when the Reaction bundle is resolved in order for it to be used.

If the OSGi logging service is not available on startup - or subsequently becomes unavailable during operation - logging is redirected to a backup log service instead. The backup log service to be used is specified as part of the constructor for the OSGi log service wrapper and will typically be an instantiation of the console output logger. The OSGi log service wrapper component is present in the OSGi package as ReactorLogOsgiOptional.