| MAP | PTLog Documents > Tutorial > PTLog Basic > 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.
In this tutorial, abbreviated class names are used. Complete names are shown below.
| 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 |
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);
}
LogTapIn 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.
NullLogServerLogTap constructor which has only "subject" parameter.
WriterProviderjava.io.Writer.
This class has not only STDOUT(as standard out),
but also STDERR(as standard out) class fields for convenience.
LogAPIProviderLog4jProviderJCLProviderSo, 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
}
LogTap using JDK Logging APIAs 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)
}
LogTap using NullLogServerThen,
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
From a different viewpoint,
invocation of LogTap#setServer(NullLogServer.INSTANCE)
allows you to prevent each LogTaps
from requesting to underlying framework separately.
| MAP | PTLog Documents > Tutorial > PTLog Basic > Plug into logging framework | << | >> |