Home of: [Atelier "FUJIGURUMA"] >> [PTLog hosted by SourceForge.net]

SEE "For Readers of English Version",
or Japanese version of this page

Plug into logging framework

This section explains how to choose underlying logging framework.

Please see also classes belonging to basic.plug package of demonstration implementation.

Overview

Class names

In this tutorial, abbreviated class names are used. Complete names are shown below.

Classes of PTLog

Notation Full name
JCLProvider jp.ne.dti.lares.foozy.ptlog.jcl.JCLProvider
Log4jProvider jp.ne.dti.lares.foozy.ptlog.log4j.Log4jProvider
LogAPIProvider jp.ne.dti.lares.foozy.ptlog.logapi.LogAPIProvider
LogTap jp.ne.dti.lares.foozy.ptlog.LogTap
NullLogServer jp.ne.dti.lares.foozy.ptlog.NullLogServer
WriterProvider jp.ne.dti.lares.foozy.ptlog.writer.WriterProvider

Specify initial logging framework

In the former section, LogTap creation code is written as shown below.


public class Client
{
    ....

    final static
    public LogTap TAP =
    new LogTap(Client.class, WriterProvider.STDOUT);
}

Create LogTap

In this example, we use WriterProvider.STDOUT to specify standard out as a kind of underlying logging framework.

To specify underlying logging framework, PTLog provides some variations as shown below.

NullLogServer
means that no logging request is written out. This is used by LogTap constructor which has only "subject" parameter.
WriterProvider
means that logging requests are written out to specified java.io.Writer. This class has not only STDOUT(as standard out), but also STDERR(as standard out) class fields for convenience.
LogAPIProvider
means that logging requests are written out via JDK Logging API framework.
Log4jProvider
means that logging requests are written out via Apache Log4j framework.
JCLProvider
means that logging requests are written out via Jakarta Commons Logging framework.

So, you can specify logging framework other than standard out as initial one. For example:


public class Client
{
    ....

    final static
    public LogTap TAP =
    new LogTap(Client.class, LogAPIProvider.INSTANCE);
    // uses JDK Logging API as initial logging framework
}

Create LogTap using JDK Logging API

Plug into logging framework

As described before, you can specify any logging frameowrk as initial underlying one for LogTap of logging client code.

But underlying logging framework is usually determined at runtime, and should not be specified at LogTap creation time. Ordinarily, you should create LogTap with NullLogServer, which means that no logging request is written out.


public class Client
{
    ....

    final static
    public LogTap TAP = new LogTap(Client.class);
    // is equivalent to
    //     new LogTap(Client.class, NullLogServer.INSTANCE)
}

Create LogTap using NullLogServer

Then, you can specify underlying logging framework as shown below. This invocation will be placed in "main(String[])" (or other similar, contextInitialized() of ServletContextListener for example) method to determine logging framework at runtime.


    Client.TAP.setServer(Log4jProvider.INSTANCE);
    // uses Apache Log4j as underlying framework

Plug into logging framework

From a different viewpoint, invocation of LogTap#setServer(NullLogServer.INSTANCE) allows you to prevent each LogTaps from requesting to underlying framework separately.


To next section "Bundle taps"