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

dk.rode.thesis.meta.log
Interface Log

All Known Implementing Classes:
AbstractLog, AppendableLog, FileLog, NullLog

public interface Log

A very simple logger used in this project.

Logs are either associated with a specific class, or a default global log.

Logs are created by a LogFactory object.

Author:
Gunni Rode / rode.dk

Method Summary
 Log error(Object... messages)
          Logs each part of an error message supplied in messages with this log as is, no trailing new line or white space inserted between message parts, but with a single new line character after the last part as well as a prefix indicating the message represent an error message.
 int getLineNumber()
          If this log logs line numbers, the current line number is returned; otherwise 0.
 String getPrefix()
          Returns the prefix of this log that will be prefixed to all log messages starting at a new line.
 Log heading(Object... messages)
          Logs each part of a heading supplied in messages with this log as is, no trailing new line or white space inserted between heading parts, but with a single new line character after the last part, underscored on the next log line.
 boolean isActive()
          Returns true if this log is active, i.e. logs messages, false if inactive.
 Log print(boolean condition, Object... messages)
          Logs each message part supplied in messages with this log as is, no trailing new line or white space inserted between messages, if and only if condition is true.
 Log print(Object... messages)
          Logs each message part supplied in messages with this log as is, no trailing new line or white space inserted between messages.
 Log println(boolean condition, Object... messages)
          Logs each message part supplied in messages with this log as is, no trailing new line or white space inserted between messages, if and only if condition is true, but always with a single new line character after the last part.
 Log println(Object... messages)
          Logs each message part supplied in messages with this log as is, no trailing new line or white space inserted between messages, but with a single new line character after the last part.
 Log setActive(boolean active)
          If active is true, this log is set to active, i.e. to log messages.
 Log warn(Object... messages)
          Logs each part of a warning message supplied in messages with this log as is, no trailing new line or white space inserted between message parts, but with a single new line character after the last part as well as a prefix indicating the message represent a warning message.
 

Method Detail

error

Log error(Object... messages)
Logs each part of an error message supplied in messages with this log as is, no trailing new line or white space inserted between message parts, but with a single new line character after the last part as well as a prefix indicating the message represent an error message.

A part that is null is logged as the string null.

Example (default log):

   error("This", "is ", " an ", "error"):
   
   MAIN:xxx:123:: > ERROR - Thisis  an error(newline)
 
Where xxx is the name of the member invoking the error method and 123 the line number.

Parameters:
messages - The message parts; can be null, corresponding to a single new line being printed.
Returns:
This log; never null.

getLineNumber

int getLineNumber()
If this log logs line numbers, the current line number is returned; otherwise 0.

Returns:
The current line number, or null if line numbers are not logged.

getPrefix

String getPrefix()
Returns the prefix of this log that will be prefixed to all log messages starting at a new line.

Returns:
The prefix.

heading

Log heading(Object... messages)
Logs each part of a heading supplied in messages with this log as is, no trailing new line or white space inserted between heading parts, but with a single new line character after the last part, underscored on the next log line.

A message that is null is logged as the string null.

Example (default log):

   heading("This", "is ", " a ", "heading"):
   
   (newline)
   MAIN:xxx:123:: Thisis  a heading(newline)
   MAIN:xxx:123:: =================(newline)
   (newline)
   (newline)
 
Where xxx is the name of the member invoking the heading method and 123 the line number.

Parameters:
messages - The message parts; can be null, corresponding to a single new line being printed (no underscore).
Returns:
This log; never null.

isActive

boolean isActive()
Returns true if this log is active, i.e. logs messages, false if inactive.

Returns:
True if active, false if inactive.

print

Log print(boolean condition,
          Object... messages)
Logs each message part supplied in messages with this log as is, no trailing new line or white space inserted between messages, if and only if condition is true.

A part that is null is logged as the string null.

Example (default log):

   i = 1;
   ..
   print(i > 0, "This", "is ", "message #", new Integer(42), "!"):
   
   MAIN:xxx:123:: Thisis message #42!
   
   ..
   
   i = 0;
   ..
   print(i > 0, "This", "is ", "message #", new Integer(42), "!"):
   
   (nothing logged)
 
Where xxx is the name of the member invoking the print method and 123 the line number.

Parameters:
condition - The condition to use.
messages - The message parts; can be null, which will not print anything.
Returns:
This log; never null.

print

Log print(Object... messages)
Logs each message part supplied in messages with this log as is, no trailing new line or white space inserted between messages.

A part that is null is logged as the string null.

Example (default log):

   print("This", "is ", "message #", new Integer(42), "!"):
   
   MAIN:xxx:123:: Thisis message #42!
 
Where xxx is the name of the member invoking the print method and 123 the line number.

Parameters:
messages - The message parts; can be null, which will not print anything.
Returns:
This log; never null.

println

Log println(boolean condition,
            Object... messages)
Logs each message part supplied in messages with this log as is, no trailing new line or white space inserted between messages, if and only if condition is true, but always with a single new line character after the last part. Hence, if condition is false, the effect is equivalent to println().

A part that is null is logged as the string null.

Example (default log):

   i = 1;
   ..
   println(i > 0, "This", "is ", "message #", new Integer(42), "!"):
   
   MAIN:xxx:123:: Thisis message #42!(newline)
   
   ..
   
   i = 0;
   ..
   println(i > 0, "This", "is ", "message #", new Integer(42), "!"):
   
   (newline logged only)
 
Where xxx is the name of the member invoking the println method and 123 the line number.

Parameters:
condition - The condition to use.
messages - The message parts; can be null, corresponding to a single new line being printed.
Returns:
This log; never null.

println

Log println(Object... messages)
Logs each message part supplied in messages with this log as is, no trailing new line or white space inserted between messages, but with a single new line character after the last part.

A part that is null is logged as the string null.

Example (default log):

   println("This", "is ", "message #", new Integer(42), "!"):
   
   MAIN:xxx:123:: Thisis message #42!(newline)
 
Where xxx is the name of the member invoking the println method and 123 the line number.

Parameters:
messages - The message parts; can be null, corresponding to a single new line being printed.
Returns:
This log; never null.

setActive

Log setActive(boolean active)
If active is true, this log is set to active, i.e. to log messages.

Parameters:
active - True to (re-)activate, false to disable.
Returns:
This log; never null.

warn

Log warn(Object... messages)
Logs each part of a warning message supplied in messages with this log as is, no trailing new line or white space inserted between message parts, but with a single new line character after the last part as well as a prefix indicating the message represent a warning message.

A part that is null is logged as the string null.

Example (default log):

   warn("This", "is ", " a", "warning"):
   
   MAIN:xxx:123:: > WARN - Thisis  awarning(newline)
 
Where xxx is the name of the member invoking the warn method and 123 the line number.

Parameters:
messages - The message parts; can be null, corresponding to a single new line being printed.
Returns:
This log; never null.

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.