org.pf.logging
Class PrintStreamLogger

java.lang.Object
  extended by org.pf.logging.PrintStreamLogger
All Implemented Interfaces:
Logger

public class PrintStreamLogger
extends java.lang.Object
implements Logger

This logger supports simple output to a print stream. By default that print stream is stdout. But it can changed by setting the property 'logging.printstream.file' to a filename. Then it will open that file at first access and appends all output to it.

The initial log level is ERROR. It can be changed via the property 'logging.level' (e.g. logging.level=WARNING).

Version:
1.2
Author:
Manfred Duchrow

Field Summary
static int LEVEL_DEBUG
          This log level specifies that all messages will be logged
static int LEVEL_ERROR
          This log level specifies that only error messages will be logged
static int LEVEL_INFO
          This log level specifies that only error, warning and info messages will be logged
static int LEVEL_NONE
          This log level specifies that no message at all will be logged
static int LEVEL_WARN
          This log level specifies that only error and warning messages will be logged
static java.lang.String LL_DEBUG
          This is the log level string representation for DEBUG
static java.lang.String LL_ERROR
          This is the log level string representation for ERROR
static java.lang.String LL_INFO
          This is the log level string representation for INFO
static java.lang.String LL_NONE
          This is the log level string representation for NONE
static java.lang.String LL_WARNING
          This is the log level string representation for WARNING
static java.lang.String PROP_LOG_LEVEL
          The property to set the log level.
static java.lang.String PROP_OUTPUT_FILE
          The property that specifies a filename to redirect the log output "logging.printstream.file"
 
Constructor Summary
PrintStreamLogger()
          Initialize the new instance with default values.
 
Method Summary
 int getLogLevel()
          Returns the current log level
 void initialize(java.util.Properties properties)
          Initialize the logger from the given properties settings.
 boolean isLoggingDebugs()
          Returns true, if debug messages will be written to the output device(s).
 boolean isLoggingErrors()
          Returns true, if errors will be written to the output device(s).
 boolean isLoggingInfos()
          Returns true, if info messages will be written to the output device(s).
 boolean isLoggingWarnings()
          Returns true, if warnings will be written to the output device(s).
 void logDebug(java.lang.String message)
          If the logging level is DEBUG the given message will be written to the log output device(s).
 void logError(java.lang.String message)
          If the logging level is DEBUG, INFO, WARNING or ERROR the given message will be written to the log output device(s).
 void logError(java.lang.String message, java.lang.Throwable exception)
          If the logging level is DEBUG, INFO, WARNING or ERROR the given message and the exception will be written to the log output device(s).
 void logException(java.lang.Throwable ex)
          Writes the given exception to the log output device(s).
 void logInfo(java.lang.String message)
          If the logging level is INFO or DEBUG the given message will be written to the log output device(s).
 void logWarning(java.lang.String message)
          If the logging level is DEBUG, INFO or WARNING the given message will be written to the log output device(s).
 void logWarning(java.lang.String message, java.lang.Throwable exception)
          If the logging level is DEBUG, INFO or WARNING the given message and the exception will be written to the log output device(s).
 void setLogLevel(int newLevel)
          Set the current log level of this logger.
 boolean setLogLevel(java.lang.String logLevel)
          Changes the log level to the specified level.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEVEL_NONE

public static final int LEVEL_NONE
This log level specifies that no message at all will be logged

See Also:
Constant Field Values

LEVEL_ERROR

public static final int LEVEL_ERROR
This log level specifies that only error messages will be logged

See Also:
Constant Field Values

LEVEL_WARN

public static final int LEVEL_WARN
This log level specifies that only error and warning messages will be logged

See Also:
Constant Field Values

LEVEL_INFO

public static final int LEVEL_INFO
This log level specifies that only error, warning and info messages will be logged

See Also:
Constant Field Values

LEVEL_DEBUG

public static final int LEVEL_DEBUG
This log level specifies that all messages will be logged

See Also:
Constant Field Values

LL_NONE

public static final java.lang.String LL_NONE
This is the log level string representation for NONE

See Also:
Constant Field Values

LL_ERROR

public static final java.lang.String LL_ERROR
This is the log level string representation for ERROR

See Also:
Constant Field Values

LL_WARNING

public static final java.lang.String LL_WARNING
This is the log level string representation for WARNING

See Also:
Constant Field Values

LL_INFO

public static final java.lang.String LL_INFO
This is the log level string representation for INFO

See Also:
Constant Field Values

LL_DEBUG

public static final java.lang.String LL_DEBUG
This is the log level string representation for DEBUG

See Also:
Constant Field Values

PROP_OUTPUT_FILE

public static final java.lang.String PROP_OUTPUT_FILE
The property that specifies a filename to redirect the log output

"logging.printstream.file"

See Also:
Constant Field Values

PROP_LOG_LEVEL

public static final java.lang.String PROP_LOG_LEVEL
The property to set the log level. The value must be one of the following strings: "NONE", "ERROR", "WARNING", "INFO", "DEBUG"

"logging.level"

See Also:
Constant Field Values
Constructor Detail

PrintStreamLogger

public PrintStreamLogger()
Initialize the new instance with default values.

Method Detail

getLogLevel

public int getLogLevel()
Returns the current log level


setLogLevel

public void setLogLevel(int newLevel)
Set the current log level of this logger.
The default is LEVEL_ERROR.

Parameters:
newLevel - The new log level (i.e. one of the LEVEL_ constants of this class)

initialize

public void initialize(java.util.Properties properties)
Initialize the logger from the given properties settings. Currently the following properties are supported:
logging.printstream.file
The name of a file to which all logging should be redirected
logging.level
The log level. Must be one of "NONE", "ERROR", "WARNING", "INFO", "DEBUG"

Specified by:
initialize in interface Logger

logException

public void logException(java.lang.Throwable ex)
Writes the given exception to the log output device(s). The log level will be ignored.

Specified by:
logException in interface Logger

logDebug

public void logDebug(java.lang.String message)
If the logging level is DEBUG the given message will be written to the log output device(s).

Specified by:
logDebug in interface Logger

logInfo

public void logInfo(java.lang.String message)
If the logging level is INFO or DEBUG the given message will be written to the log output device(s).

Specified by:
logInfo in interface Logger

logWarning

public void logWarning(java.lang.String message)
If the logging level is DEBUG, INFO or WARNING the given message will be written to the log output device(s).

Specified by:
logWarning in interface Logger

logError

public void logError(java.lang.String message)
If the logging level is DEBUG, INFO, WARNING or ERROR the given message will be written to the log output device(s).

Specified by:
logError in interface Logger

logWarning

public void logWarning(java.lang.String message,
                       java.lang.Throwable exception)
If the logging level is DEBUG, INFO or WARNING the given message and the exception will be written to the log output device(s).

Specified by:
logWarning in interface Logger

logError

public void logError(java.lang.String message,
                     java.lang.Throwable exception)
If the logging level is DEBUG, INFO, WARNING or ERROR the given message and the exception will be written to the log output device(s).

Specified by:
logError in interface Logger

isLoggingDebugs

public boolean isLoggingDebugs()
Returns true, if debug messages will be written to the output device(s).

Specified by:
isLoggingDebugs in interface Logger

isLoggingInfos

public boolean isLoggingInfos()
Returns true, if info messages will be written to the output device(s).

Specified by:
isLoggingInfos in interface Logger

isLoggingWarnings

public boolean isLoggingWarnings()
Returns true, if warnings will be written to the output device(s).

Specified by:
isLoggingWarnings in interface Logger

isLoggingErrors

public boolean isLoggingErrors()
Returns true, if errors will be written to the output device(s).

Specified by:
isLoggingErrors in interface Logger

setLogLevel

public boolean setLogLevel(java.lang.String logLevel)
Changes the log level to the specified level. Returns true if the level is supported and was set, otherwise false.

Specified by:
setLogLevel in interface Logger
Returns:
Always false for this logger