PTLog API - 1.0

jp.ne.dti.lares.foozy.ptlog.writer
Class WriterProvider

java.lang.Object
  extended byjp.ne.dti.lares.foozy.ptlog.LogServer
      extended byjp.ne.dti.lares.foozy.ptlog.EffectiveLogServer
          extended byjp.ne.dti.lares.foozy.ptlog.ServiceProvider
              extended byjp.ne.dti.lares.foozy.ptlog.writer.WriterProvider

public class WriterProvider
extends ServiceProvider

Log service provider to write log out to specified Writer.

There are two ways to use this service provider.

One of them is construction of LogTaps with this(e.g.: STDOUT).

Another way is invocation of setServer with this(e.g.: STDOUT) on your LogTaps (or setServer on your LogDirector). This allows you to change configuration at runtime.

Specific featuress of this service provider are:

ATTENTION:

This class invokes constructor of base class with:

So, TypeConverter, which is registered to this, should convert from LogType to java.lang.String.


Field Summary
static WriterProvider STDERR
          Convenience to use this class for standard-err without construction.
static WriterProvider STDOUT
          Convenience to use this class for standard-out without construction.
 
Constructor Summary
WriterProvider(java.io.Writer writer)
          Constructor.
WriterProvider(java.io.Writer writer, boolean switchable)
          Constructor.
 
Method Summary
protected  boolean enables(LogType type, java.lang.String subject, java.lang.String method)
          Examine loggability of specified type/subject/method.
 LogContext getContext(java.lang.Object subject)
          Return WriterLogContext.
 boolean isSwitchable()
          Return whether this instance allows writer switching.
protected  void log(LogType type, java.lang.String subject, java.lang.String method, java.lang.String message, java.lang.Throwable throwable)
          Write logging record out to writer.
 void setFilter(LogFilter filter)
          Set filter to specified one.
 void setFormatter(LogFormatter formatter)
          Set log formatter to specified one.
 java.io.Writer setWriter(java.io.Writer writer)
          Use specified writer as new log destination.
 
Methods inherited from class jp.ne.dti.lares.foozy.ptlog.ServiceProvider
addTypeConverter, addTypeConverters, clearTypeConverter, convertType, removeTypeConverter
 
Methods inherited from class jp.ne.dti.lares.foozy.ptlog.EffectiveLogServer
addServee_, getServees, removeServee_
 
Methods inherited from class jp.ne.dti.lares.foozy.ptlog.LogServer
addServee, fireReconfigure, getSubjectName, removeServee
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STDOUT

public static final WriterProvider STDOUT
Convenience to use this class for standard-out without construction.

This is constructed by WriterProvider( CloseGuard.STDOUT_WRITER, false), so you can not invoke setWriter(java.io.Writer).

Please construct by WriterProvider( CloseGuard.STDOUT_WRITER, true) if you want to switch Writer.


STDERR

public static final WriterProvider STDERR
Convenience to use this class for standard-err without construction.

This is constructed by WriterProvider( CloseGuard.STDERR_WRITER, false), so you can not invoke setWriter(java.io.Writer).

Please construct by WriterProvider( CloseGuard.STDERR_WRITER, true) if you want to switch Writer.

Constructor Detail

WriterProvider

public WriterProvider(java.io.Writer writer,
                      boolean switchable)
Constructor.

null writer means CloseGuard.STDOUT_WRITER.

For resource efficiency, please use STDOUT for standard out (or STDERR for standard error) instead of NEW-ing, except of invocation from derived classes.

ATTENTION: "Closing specified writer" is not responsibility of this class but of user side.

Parameters:
writer - on which logging information is writen.
switchable - whether setWriter(java.io.Writer) invocation is allowed.

WriterProvider

public WriterProvider(java.io.Writer writer)
Constructor.

This is equivalent to WriterProvider(writer, true) .

Method Detail

isSwitchable

public final boolean isSwitchable()
Return whether this instance allows writer switching.

See Also:
setWriter(java.io.Writer)

setWriter

public final java.io.Writer setWriter(java.io.Writer writer)
Use specified writer as new log destination.

This does:

  1. examine switchability, and throws runtime exception if it returns false
  2. change destination from old to specified one
  3. return old destination writer

null writer means CloseGuard.STDOUT_WRITER.

ATTENTION: "Closing old writer" is not responsibility of this class but of caller side.

So, typical invocation code is:

     provider.setWriter(newWriter).close();
 

Please consider to use CloseGuard.StreamWrapper or CloseGuard.WriterWrapper, if you want not to close some streams/writers but to close the other ones.

Parameters:
writer - new log destination
Returns:
old destination writer

setFilter

public final void setFilter(LogFilter filter)
Set filter to specified one.

null filter means AcceptFilter.ALL.

Parameters:
filter - of logging
See Also:
PropertiesFilterConfig

setFormatter

public final void setFormatter(LogFormatter formatter)
Set log formatter to specified one.

null formatter means DefaultLogFormatter.INSTANCE.

Parameters:
formatter - to format log information

enables

protected final boolean enables(LogType type,
                                java.lang.String subject,
                                java.lang.String method)
Examine loggability of specified type/subject/method.

See Also:
setFilter(jp.ne.dti.lares.foozy.ptlog.writer.LogFilter)

log

protected final void log(LogType type,
                         java.lang.String subject,
                         java.lang.String method,
                         java.lang.String message,
                         java.lang.Throwable throwable)
Write logging record out to writer.

This writes logging record out, if specified logging request is enables.

Logging record is formatted by specified formatter.


getContext

public LogContext getContext(java.lang.Object subject)
Return WriterLogContext.

Specified by:
getContext in class LogServer
Parameters:
subject - of logging request.
Returns:
context for specified subject.

PTLog API - 1.0