3.6. Custom Log
Prev | Chapter 3. Logging | Next

## 3.6. Custom Log

If none of available logging systems meet your needs, the logging system can be configured to use a custom logging class. 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 log class example 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 could use the following setting:

    kodo.Log: com.xyz.CustomLogFactory(Prefix="LOG MSG")

Prev | Up | Next
3.5. Apache Commons Logging | Home | Chapter 4. JDBC