3.6. Custom Log

If none of available logging systems meet your needs, you can configure the logging system with a custom logger. You might use custom logging to integrate with a proprietary logging framework used by some applications servers, or for logging to a graphical component for GUI applications.

A custom logging framework must include an implementation of the com.solarmetric.log.LogFactory interface. We present a custom LogFactory below.

Example 3.6. Custom Logging Class

package com.xyz;

import com.solarmetric.log.*;

public class CustomLogFactory
    implements LogFactory
    private String _prefix = "CUSTOM LOG";

    public void setPrefix (String prefix)
        _prefix = prefix;
    public Log getLog (String channel)
        // Return a simple extension of AbstractLog that will log
        // everything to the System.err stream. Note that this is 
        // roughly equivalent to Kodo's default logging behavior.
        return new AbstractLog ()
            protected boolean isEnabled (short logLevel)
                // log all levels
                return true;

            protected void log (short type, String message, Throwable t)
                // just send everything to System.err
                System.err.println (_prefix + ": " + type + ": "
                    + message + ": " + t);

To make Kodo use your custom log factory, set the kodo.Log configuration property to your factory's full class name. Because this property is a plugin property (see Section 2.4, “Plugin Configuration”), you can also pass parameters to your factory. For example, to use the example factory above and set its prefix to "LOG MSG", you would set the kodo.Log property to the following string:

com.xyz.CustomLogFactory(Prefix="LOG MSG")


Skip navigation bar   Back to Top