The Meta-Environment API

toolbus.logging
Class CommandLineLogger

java.lang.Object
  extended by toolbus.logging.CommandLineLogger
All Implemented Interfaces:
ILogger

public class CommandLineLogger
extends java.lang.Object
implements ILogger

Logger implementation that writes to the command line / std-err.

Author:
Arnold Lankamp

Field Summary
private  int level
           
private  java.io.PrintStream printStream
           
private  boolean timestamp
           
 
Fields inherited from interface toolbus.logging.ILogger
ALL, DEBUG, DEBUGSTR, ERROR, ERRORSTR, FATAL, FATALSTR, INFO, INFOSTR, LOG, LOGSTR, OFF, UNKNOWNSTR, WARNING, WARNINGSTR
 
Constructor Summary
CommandLineLogger()
          Default constructor.
CommandLineLogger(int level)
          Constructor.
 
Method Summary
static java.lang.String getFormattedDateTime()
          Returns a properly formated string containing the date and time.
static java.lang.String getLogLevelString(int logLevel)
          Returns a string containing a string representation of the log level.
 void log(java.lang.String message, int loglevel)
          Logs the given message (but only if the message is 'important' enough).
 void log(java.lang.String message, java.lang.Throwable throwable, int loglevel)
          Logs the given message, including the given stacktrace (but only if the message is 'important' enough).
 void setTimestamp(boolean on)
          Toggle timestamp printing in messages
private  boolean shouldLog(int loglevel)
          Method for checking if we should log a message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

level

private final int level

printStream

private final java.io.PrintStream printStream

timestamp

private boolean timestamp
Constructor Detail

CommandLineLogger

CommandLineLogger()
Default constructor. Inititalizes this logger with the default log level (WARNING).


CommandLineLogger

CommandLineLogger(int level)
Constructor. Initialized this logger with the given log level.

Parameters:
level - The log level to initialize this logger with.
Method Detail

shouldLog

private boolean shouldLog(int loglevel)
Method for checking if we should log a message. This depends on the log level and the given log level.

Parameters:
loglevel - The log level of the message.
Returns:
True if we should log the message with the given log level, false otherwise.

setTimestamp

public void setTimestamp(boolean on)
Description copied from interface: ILogger
Toggle timestamp printing in messages

Specified by:
setTimestamp in interface ILogger
Parameters:
on - Sets timestamp on or off.

log

public void log(java.lang.String message,
                int loglevel)
Description copied from interface: ILogger
Logs the given message (but only if the message is 'important' enough).

Specified by:
log in interface ILogger
Parameters:
message - The message that needs to be logged.
loglevel - The log level of the message.
See Also:
ILogger.log(String, int)

log

public void log(java.lang.String message,
                java.lang.Throwable throwable,
                int loglevel)
Description copied from interface: ILogger
Logs the given message, including the given stacktrace (but only if the message is 'important' enough).

Specified by:
log in interface ILogger
Parameters:
message - The message that needs to be logged.
throwable - The stacktrace associated with the message.
loglevel - The log level of the message.
See Also:
ILogger.log(String, Throwable, int)

getFormattedDateTime

public static java.lang.String getFormattedDateTime()
Returns a properly formated string containing the date and time.

Returns:
A properly formated string containing the date and time.

getLogLevelString

public static java.lang.String getLogLevelString(int logLevel)
Returns a string containing a string representation of the log level.

Parameters:
logLevel - The log level we want the string representation of.
Returns:
The string representation of the given log level.

The Meta-Environment API