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);
}
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
LogTap
constructor which has only "subject" parameter.
WriterProvider
java.io.Writer
.
This class has not only STDOUT
(as standard out),
but also STDERR
(as standard out) class fields for convenience.
LogAPIProvider
Log4jProvider
JCLProvider
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
}
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)
}
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
From a different viewpoint,
invocation of LogTap#setServer(NullLogServer.INSTANCE)
allows you to prevent each LogTap
s
from requesting to underlying framework separately.
MAP | PTLog Documents > Tutorial > PTLog Basic > Plug into logging framework | << | >> |