Holger's
Java API

com.antelmann.util.logging
Class AbstractLogWriter<T>

java.lang.Object
  extended by com.antelmann.util.logging.AbstractLogWriter<T>
All Implemented Interfaces:
Filter<LogEntry>, LogWriter
Direct Known Subclasses:
AbstractExceptionWriter, AppendableLogWriter, BinaryFileLog, FileLog, JDBCLogWriter, JTextAreaLog, JTextComponentLog, LogFile, LogNetPropagator, SocketWriter, StackTraceFileWriter, XMLLogWriter

public abstract class AbstractLogWriter<T>
extends Object
implements LogWriter

provides filtering capabilities for a LogWriter. Extending classes only need to implement writeLogPattern(Object).

Author:
Holger Antelmann

Field Summary
protected  Filter<? super LogEntry> filter
          may be null (in which case all LogEntry objects are written)
 
Fields inherited from interface com.antelmann.util.Filter
EXCLUDE_ALL_FILTER, INCLUDE_ALL_FILTER
 
Constructor Summary
protected AbstractLogWriter(LogEntryFormatter<T> formatter)
           
protected AbstractLogWriter(LogEntryFormatter<T> formatter, Filter<? super LogEntry> filter)
           
 
Method Summary
 boolean accept(LogEntry entry)
          returns true if either the filter is null or the filter accepts the given entry
 Filter<? super LogEntry> getLogFilter()
           
 LogEntryFormatter<T> getLogFormatter()
           
 void setLogFilter(Filter<? super LogEntry> filter)
           
 void setLogFormatter(LogEntryFormatter<T> formatter)
          formatter must not be null
 void write(LogEntry entry)
          normally not to be overridden; directly calls writeLogPattern w/o double-checking the filter
protected abstract  void writeLogPattern(T pattern)
          writes the pattern to the log entity.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

filter

protected Filter<? super LogEntry> filter
may be null (in which case all LogEntry objects are written)

Constructor Detail

AbstractLogWriter

protected AbstractLogWriter(LogEntryFormatter<T> formatter)

AbstractLogWriter

protected AbstractLogWriter(LogEntryFormatter<T> formatter,
                            Filter<? super LogEntry> filter)
Method Detail

getLogFilter

public Filter<? super LogEntry> getLogFilter()

setLogFilter

public void setLogFilter(Filter<? super LogEntry> filter)

accept

public boolean accept(LogEntry entry)
returns true if either the filter is null or the filter accepts the given entry

Specified by:
accept in interface Filter<LogEntry>

write

public void write(LogEntry entry)
           throws LogException
normally not to be overridden; directly calls writeLogPattern w/o double-checking the filter

Specified by:
write in interface LogWriter
Throws:
LogException - if an error occurred while writing the log

writeLogPattern

protected abstract void writeLogPattern(T pattern)
                                 throws LogException
writes the pattern to the log entity. If the LogEntryFormatter is null, the pattern is the LogEntry object itself; otherwise, the pattern is the result of formatting the LogEntry with the given LogEntryFormatter.

Throws:
LogException

getLogFormatter

public LogEntryFormatter<T> getLogFormatter()

setLogFormatter

public void setLogFormatter(LogEntryFormatter<T> formatter)
                     throws NullPointerException
formatter must not be null

Throws:
NullPointerException


(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads