Evaluating Software Design Patterns
— the "Gang of Four" patterns implemented in Java 6

dk.rode.thesis.meta.log
Class AppendableLog

java.lang.Object
  extended by dk.rode.thesis.meta.log.AbstractLog
      extended by dk.rode.thesis.meta.log.AppendableLog
All Implemented Interfaces:
Log
Direct Known Subclasses:
FileLog

public class AppendableLog
extends AbstractLog
implements Log

An appendable log uses an Appendable object as the target for log messages, for example a PrintStream such as System.out.

Author:
Gunni Rode / rode.dk

Field Summary
private  boolean close
          True if out should be closed when this log goes out of scope, false if not.
private  Appendable out
          The target for log messages.
 
Constructor Summary
AppendableLog(Appendable out, boolean close, Class<?> clazz, boolean active, AtomicInteger lineNumber)
          Constructor, which creates this log as active if active is true.
AppendableLog(Appendable out, Class<?> clazz)
          Constructor, which creates this log as active.
 
Method Summary
protected  void finalize()
          Closes the appendable used by this logger if so specified at construction time and if the appendable is closeable.
protected  void log(Object... messages)
          Performs the actual logging of the messages supplied as messages with no new line postfixed.
 
Methods inherited from class dk.rode.thesis.meta.log.AbstractLog
error, format, getLineNumber, getPrefix, getPrefix, heading, isActive, print, print, println, println, setActive, toString, warn
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface dk.rode.thesis.meta.log.Log
error, getLineNumber, getPrefix, heading, isActive, print, print, println, println, setActive, warn
 

Field Detail

close

private final boolean close
True if out should be closed when this log goes out of scope, false if not.


out

private final Appendable out
The target for log messages.

Never null.

Constructor Detail

AppendableLog

AppendableLog(Appendable out,
              boolean close,
              Class<?> clazz,
              boolean active,
              AtomicInteger lineNumber)
Constructor, which creates this log as active if active is true.

out is closed by this log if close is true.

Parameters:
out - The target for log messages; cannot be null.
close - True to close out when this log goes out of scope.
clazz - The class this log is associated with, if any; can be null.
active - True if this log is initially active, false if not.
lineNumber - Line number values; can be null, in which case line numbers are not generated.
Throws:
NullPointerException - If out is null.
See Also:
AbstractLog.isActive()

AppendableLog

AppendableLog(Appendable out,
              Class<?> clazz)
Constructor, which creates this log as active.

out is not closed by this log.

No line numbers are logged.

Parameters:
out - The target for log messages; cannot be null.
clazz - The class this log is associated with, if any; can be null.
Throws:
NullPointerException - If out is null.
Method Detail

finalize

protected void finalize()
Closes the appendable used by this logger if so specified at construction time and if the appendable is closeable.

Overrides:
finalize in class Object

log

protected void log(Object... messages)
            throws IOException
Description copied from class: AbstractLog
Performs the actual logging of the messages supplied as messages with no new line postfixed.

All messages part are assumed to have a meaningful toString() representation and are not null, and there is no need for explicit formatting.

Specified by:
log in class AbstractLog
Parameters:
messages - The messages to log; never null.
Throws:
IOException - In case an exception occurs while logging.

Gunni Rode / rode.dk

Feel free to use and/or modify the Java 6 source code developed for this thesis AT YOUR OWN RISK, but note that the source code comes WITHOUT ANY — and I do mean WITHOUT ANY — form of warranty WHAT SO EVER!

The original thesis and source code are available at rode.dk/thesis.