edu.isi.pegasus.common.logging.logger
Class Default

java.lang.Object
  extended by edu.isi.pegasus.common.logging.LogManager
      extended by edu.isi.pegasus.common.logging.logger.Default

public class Default
extends LogManager

The logging class that to log messages at different levels. Currently the following levels are supported.

Eventually, each of the level can have a different writer stream underneath.

The messages can be logged at various levels. The various levels of logging with increasing levels of verbosity are displayed in the following table.

Logging LevelDescription
FATAL all fatal error messages are logged in this level.
ERROR all non fatal error messages are logged in this level.
WARNING all warning messages are logged in this level.
INFO all information logging messages are logged in this level.
CONFIG all configuration messages are logged in this level.
DEBUG all debug messages are logged in this level.

Version:
$Revision: 4280 $
Author:
Karan Vahi, Gaurang Mehta

Field Summary
private static int CONFIG_MESSAGE_TYPE
          The type value to indicate a CONFIG message.
private static int CONSOLE_MESSAGE_TYPE
          The type value to indicate a CONSOLE message.
private static int DEBUG_MESSAGE_TYPE
          The type value to indicate a DEBUG message.
private static int ERROR_MESSAGE_TYPE
          The type value to indicate an ERROR message.
private static int FATAL_MESSAGE_TYPE
          The type value to indicate a FATAL error message.
private static int INFO_MESSAGE_TYPE
          The type value to indicate an INFORMATIVE message.
private static Default logger
          Ensures only one object is created always.
private  PrintStream mErrStream
          The stream to which all the error messages are logged.By default it is System.err
private static Currently mFormatter
          This is used to format the time stamp.
private  int mMask
          The mask that needs to be deployed to determine what messages are to be logged.
private  PrintStream mOutStream
          The stream to which one writes.
private static int TRACE_MESSAGE_TYPE
          The type value to indicate a DEBUG message.
private static int WARNING_MESSAGE_TYPE
          The type value to indicate a WARNING message.
 
Fields inherited from class edu.isi.pegasus.common.logging.LogManager
CONFIG_MESSAGE_LEVEL, CONSOLE_MESSAGE_LEVEL, DEBUG_MESSAGE_LEVEL, DEFAULT_LOGGER, ERROR_MESSAGE_LEVEL, FATAL_MESSAGE_LEVEL, INFO_MESSAGE_LEVEL, LOG4J_LOGGER, mDebugLevel, MESSAGE_DONE_PREFIX, mLogFormatter, PROPERTIES_PREFIX, TRACE_MESSAGE_LEVEL, VERSION, WARNING_MESSAGE_LEVEL
 
Constructor Summary
Default()
          The constructor.
 
Method Summary
private  int generateMask(int level, boolean info)
          Generates the appropriate mask value, corresponding to the level passed.
 int getLevel()
          Returns the debug level.
private  String getPrefix(int type)
          Returns the prefix that needs to be logged corresponding to a particular message type, when a message is being logged.
private  PrintStream getPrintStream(int level)
          Returns a PrintWriter stream on which to log the message.
private  PrintStream getPrintStream(String out)
          Sets an internal writer to point to a particular stream.
 String getTimeStamp()
          Gets the timestamp nicely formatted.
 void initialize(LogFormatter formatter, Properties properties)
          Sets the log formatter to use for formatting the messages.
 void log(String message, Exception e, int level)
          Logs the exception on the appropriate queue if the level of the message is less than or equal to the level set for the Logger.
private  void log(String message, int level, boolean comp)
          Logs the message on the appropriate queue if the level of the message is less than or equal to the level set for the Logger.
 void logAlreadyFormattedMessage(String message, int level)
          Logs the message on the appropriate queue if the level of the message is less than or equal to the level set for the Logger.
 void logEventCompletion(int level)
          Logs the completion message on the basis of the debug level.
 void setErrorWriter(OutputStream err)
          Certains levels like FATAL, ERROR and WARN can be set to log to a different stream, than the default stream used for writing other messages.
 void setErrorWriter(String out)
          Certains levels like FATAL, ERROR and WARN can be set to log to a different stream, than the default stream used for writing other messages.
 void setLevel(int level)
          Sets the debug level.
protected  void setLevel(int level, boolean info)
          Sets the debug level.
 void setLevel(org.apache.log4j.Level level)
          Sets the debug level.
 void setOutputWriter(OutputStream out)
          Sets the writer associated with the class to the one specified for all type of messages other than error messages.
 void setOutputWriter(String out)
          Sets the writer associated with the class to the one specified for all type of messages other than error messages.
 void setWriters(String out)
          Sets both the output writer and the error writer to the same underlying writer.
 
Methods inherited from class edu.isi.pegasus.common.logging.LogManager
add, add, getInstance, log, log, logAndReset, logEntityHierarchyMessage, logEntityHierarchyMessage, logEventCompletion, logEventStart, logEventStart, logEventStart, logEventStart, sanityCheckOnDirectory, sanityCheckOnFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FATAL_MESSAGE_TYPE

private static final int FATAL_MESSAGE_TYPE
The type value to indicate a FATAL error message.

See Also:
Constant Field Values

ERROR_MESSAGE_TYPE

private static final int ERROR_MESSAGE_TYPE
The type value to indicate an ERROR message.

See Also:
Constant Field Values

CONSOLE_MESSAGE_TYPE

private static final int CONSOLE_MESSAGE_TYPE
The type value to indicate a CONSOLE message.

See Also:
Constant Field Values

WARNING_MESSAGE_TYPE

private static final int WARNING_MESSAGE_TYPE
The type value to indicate a WARNING message.

See Also:
Constant Field Values

INFO_MESSAGE_TYPE

private static final int INFO_MESSAGE_TYPE
The type value to indicate an INFORMATIVE message.

See Also:
Constant Field Values

CONFIG_MESSAGE_TYPE

private static final int CONFIG_MESSAGE_TYPE
The type value to indicate a CONFIG message.

See Also:
Constant Field Values

DEBUG_MESSAGE_TYPE

private static final int DEBUG_MESSAGE_TYPE
The type value to indicate a DEBUG message.

See Also:
Constant Field Values

TRACE_MESSAGE_TYPE

private static final int TRACE_MESSAGE_TYPE
The type value to indicate a DEBUG message.

See Also:
Constant Field Values

logger

private static Default logger
Ensures only one object is created always. Implements the Singleton.


mOutStream

private PrintStream mOutStream
The stream to which one writes. It is System.out by default for the current release. One can set it using setOutputWriter.

See Also:
setOutputWriter(java.lang.String)

mErrStream

private PrintStream mErrStream
The stream to which all the error messages are logged.By default it is System.err


mMask

private int mMask
The mask that needs to be deployed to determine what messages are to be logged.


mFormatter

private static Currently mFormatter
This is used to format the time stamp.

Constructor Detail

Default

public Default()
The constructor.

Method Detail

initialize

public void initialize(LogFormatter formatter,
                       Properties properties)
Sets the log formatter to use for formatting the messages.

Specified by:
initialize in class LogManager
Parameters:
formatter - the formatter to use.
properties - properties that the underlying implementations understand

setLevel

public void setLevel(org.apache.log4j.Level level)
Sets the debug level. All those messages are logged which have a level less than equal to the debug level.

Overrides:
setLevel in class LogManager
Parameters:
level - the level to which the debug level needs to be set to.

setLevel

public void setLevel(int level)
Sets the debug level. All those messages are logged which have a level less than equal to the debug level.

Overrides:
setLevel in class LogManager
Parameters:
level - the level to which the debug level needs to be set to.

setLevel

protected void setLevel(int level,
                        boolean info)
Sets the debug level. All those messages are logged which have a level less than equal to the debug level. In case the boolean info is set, all the info messages are also logged.

Specified by:
setLevel in class LogManager
Parameters:
level - the level to which the debug level needs to be set to.
info - boolean denoting whether the INFO messages need to be logged or not.

getLevel

public int getLevel()
Returns the debug level.

Specified by:
getLevel in class LogManager
Returns:
the level to which the debug level has been set to.

setWriters

public void setWriters(String out)
Sets both the output writer and the error writer to the same underlying writer.

Specified by:
setWriters in class LogManager
Parameters:
out - is the name of a file to append to. Special names are stdout and stderr, which map to the system's respective streams.
See Also:
#setWriters(OutputStream)

setOutputWriter

public void setOutputWriter(String out)
Sets the writer associated with the class to the one specified for all type of messages other than error messages.

Parameters:
out - is the name of a file to append to. Special names are stdout and stderr, which map to the system's respective streams.
See Also:
setOutputWriter(OutputStream)

setOutputWriter

public void setOutputWriter(OutputStream out)
Sets the writer associated with the class to the one specified for all type of messages other than error messages. By default it is System.out.

Parameters:
out - the stream to which the messages are logged.
See Also:
setErrorWriter(OutputStream)

setErrorWriter

public void setErrorWriter(String out)
Certains levels like FATAL, ERROR and WARN can be set to log to a different stream, than the default stream used for writing other messages. By default, these messages are logged to stderr. Note: The previous stream is not closed automatically.

Parameters:
out - is the name of a file to append to. Special names are stdout and stderr, which map to the system's respective streams.
See Also:
setErrorWriter(OutputStream)

setErrorWriter

public void setErrorWriter(OutputStream err)
Certains levels like FATAL, ERROR and WARN can be set to log to a different stream, than the default stream used for writing other messages. By default, these messages are logged to stderr. Note: The previous stream is not closed automatically.

Parameters:
err - the stream to which error messages are to be logged.

log

public void log(String message,
                Exception e,
                int level)
Logs the exception on the appropriate queue if the level of the message is less than or equal to the level set for the Logger. For INFO level message, the boolean indicating that a completion message is to follow is set to true always.

Specified by:
log in class LogManager
Parameters:
message - the message to be logged.
e - the exception to be logged
level - the level on which the message has to be logged.
See Also:
setLevel(int), LogManager.log(String,int)

logAlreadyFormattedMessage

public void logAlreadyFormattedMessage(String message,
                                       int level)
Logs the message on the appropriate queue if the level of the message is less than or equal to the level set for the Logger. For INFO level message, the boolean indicating that a completion message is to follow is set to true always.

Specified by:
logAlreadyFormattedMessage in class LogManager
Parameters:
message - the message to be logged.
level - the level on which the message has to be logged.
See Also:
setLevel(int), log(String,int,boolean)

log

private void log(String message,
                 int level,
                 boolean comp)
Logs the message on the appropriate queue if the level of the message is less than or equal to the level set for the Logger.

Parameters:
message - the message to be logged.
level - the level on which the message has to be logged.
comp - boolean indicating whether a completion message follows or not.
See Also:
setLevel(int)

getTimeStamp

public String getTimeStamp()
Gets the timestamp nicely formatted. It generates the date-timestamp in extended ISO 8601 format. It generates the timestamp using the local timezone not the UTC. An example of the date-timestamp generated would be 2003-06-06T14:31:27-07:00 where -07:00 denotes the timezone offset of the local timezone from UTC.

Returns:
the formattted timestamp;

logEventCompletion

public void logEventCompletion(int level)
Logs the completion message on the basis of the debug level.

Specified by:
logEventCompletion in class LogManager
Parameters:
level - the debug level of the start message for whose completion you want.

generateMask

private int generateMask(int level,
                         boolean info)
Generates the appropriate mask value, corresponding to the level passed.

Parameters:
level - the level to which the debug level needs to be set to.
info - boolean denoting whether the CONSOLE messages need to be logged or not.
Returns:
mask corresponding to the debug level passed.

getPrefix

private String getPrefix(int type)
Returns the prefix that needs to be logged corresponding to a particular message type, when a message is being logged. Should be returning an enumerated data type.

Parameters:
type - the type for which prefix is required.
Returns:
the message type

getPrintStream

private PrintStream getPrintStream(String out)
                            throws IOException
Sets an internal writer to point to a particular stream.

Parameters:
out - is the name of a file to append to. Special names are stdout and stderr, which map to the system's respective streams.
Returns:
the corresponding PrintStream.
Throws:
IOException - in case of being unable to open a stream.

getPrintStream

private PrintStream getPrintStream(int level)
Returns a PrintWriter stream on which to log the message. Later on this, function would return the appropriate LOG4J queue on which the message needs to be logged.

Parameters:
level - the level
Returns:
PrintWriter for logging the message.


Copyright © 2011 The University of Southern California. All Rights Reserved.