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

dk.rode.thesis.meta.log
Class FileLog

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

public class FileLog
extends AppendableLog
implements Log

A file log logs to a given file based on the class a given log is associated with, if any, or to the default log represented by a single physical log file.

The names of log files includes "todays" date. All logs are placed in the log directory.

Author:
Gunni Rode / rode.dk

Constructor Summary
FileLog(boolean append, Class<?> clazz, AtomicInteger lineNumber)
          Constructor, which creates this log as active.
 
Method Summary
private static Appendable create(boolean append, Class<?> clazz)
          Creates a new physical log file to use for this logger.
 
Methods inherited from class dk.rode.thesis.meta.log.AppendableLog
finalize, log
 
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
 

Constructor Detail

FileLog

FileLog(boolean append,
        Class<?> clazz,
        AtomicInteger lineNumber)
  throws Exception
Constructor, which creates this log as active.

The log will log line numbers if lineNumber is not null.

All logs are placed in the log directory.

Parameters:
append - True to append to an existing log, false to truncate.
clazz - The class this log is associated with, if any; can be null.
lineNumber - Line number values; can be null.
Throws:
NullPointerException - If directory is null.
Exception - If the creation of the file log fails.
See Also:
AbstractLog.isActive()
Method Detail

create

private static final Appendable create(boolean append,
                                       Class<?> clazz)
                                throws Exception
Creates a new physical log file to use for this logger.

The name of the log file is based on the prefix used (based on clazz) and "todays" date, such as main.2007-08-30.log, for example.

All logs are placed in the log directory.

Parameters:
append - True to append to an existing log, false to truncate.
clazz - The class the logger is associated with, if any; can be null.
Returns:
An appendable representing the file output stream; never null.
Throws:
Exception - If the creation fails.

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.