SK.gnome.dwarf.log
Class StreamLogger

java.lang.Object
  extended bySK.gnome.dwarf.GenericService
      extended bySK.gnome.dwarf.thread.ThreadService
          extended bySK.gnome.dwarf.log.GenericLogger
              extended bySK.gnome.dwarf.log.StreamLogger
All Implemented Interfaces:
Logger, java.lang.Runnable, Service
Direct Known Subclasses:
FileLogger, SystemLogger

public abstract class StreamLogger
extends GenericLogger

The abstract stream logger.

This is a logger which writes log messages to an output stream.

Subclasses must override the GenericService.init(Server) method to initialize properly the out field as well as the GenericLogger.shutdown() method to flush and close the stream.


Field Summary
protected  boolean dateTime
          Whether to write the date and time information to the stream.
protected  java.text.DateFormat dateTimeFormat
          The date/time format used to format the timestamp of the log messages.
protected  boolean extendedInfo
          Whether or not to write the logging facility and level to the stream.
protected  java.io.PrintStream out
          The output stream.
 
Fields inherited from class SK.gnome.dwarf.log.GenericLogger
facilities, levels, lock, LOG_FACILITY_ALL
 
Fields inherited from class SK.gnome.dwarf.thread.ThreadService
daemon, thread
 
Fields inherited from class SK.gnome.dwarf.GenericService
initParameters, parent
 
Fields inherited from interface SK.gnome.dwarf.Service
INITIALIZED, LOG_DEBUG, LOG_ERROR, LOG_FATAL, LOG_INFO, LOG_TRACE, LOG_WARN, LOG_XFER, SHUTDOWN, STARTED, STOPPED
 
Constructor Summary
StreamLogger(java.lang.String name)
          Creates a new StreamLogger.
 
Method Summary
 void setDateTime(boolean enable)
          Enables or disables the writting of the date and time information.
 void setDateTimeFormat(java.lang.String format)
          Sets the date/time format.
 void setDateTimeFormat(java.lang.String format, java.lang.String language, java.lang.String country)
          Sets the date/time format with the given locale.
 void setExtendedInfo(boolean enable)
          Enables or disables the writting of the logging level and facility.
protected  boolean wouldLog(java.lang.String facility, LogLevel level)
          Decides whether the logger would log a message with the given loggging level and facility.
protected  void write(long time, java.lang.String facility, LogLevel level, java.lang.String message, java.lang.Throwable error)
          Writes the message to the output stream.
 
Methods inherited from class SK.gnome.dwarf.log.GenericLogger
enableThread, getLastAccessed, log, log, loop, setFacilities, setLevels, setMarkInterval, setRepeatedInterval, shutdown, start
 
Methods inherited from class SK.gnome.dwarf.thread.ThreadService
finish, run, setDaemon, stop
 
Methods inherited from class SK.gnome.dwarf.GenericService
getAuthenticator, getAuthFacility, getFullName, getInitParameter, getInitParameterNames, getLogFacility, getLogger, getName, getParameters, getPrincipal, getShutdownTimeout, getState, init, log, log, login, logout, setAuthFacility, setInitParameters, setLogFacility, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

dateTimeFormat

protected java.text.DateFormat dateTimeFormat
The date/time format used to format the timestamp of the log messages.

Access to this value from within a subclass must be synchronized on the GenericLogger.lock object.

The default value is defined by the LogConstants.LOG_DEFAULT_DATETIME_FORMAT string.

See Also:
setDateTimeFormat(String)

dateTime

protected boolean dateTime
Whether to write the date and time information to the stream.

Default value: true

See Also:
setDateTime(boolean)

extendedInfo

protected boolean extendedInfo
Whether or not to write the logging facility and level to the stream.

Default value: false

See Also:
setExtendedInfo(boolean)

out

protected java.io.PrintStream out
The output stream.

See Also:
write(long, String, LogLevel, String, Throwable)
Constructor Detail

StreamLogger

public StreamLogger(java.lang.String name)
Creates a new StreamLogger.

Method Detail

setDateTimeFormat

public void setDateTimeFormat(java.lang.String format)
Sets the date/time format.

The format will be based on the US locale.

Parameters:
format - the date/time format
See Also:
dateTimeFormat

setDateTimeFormat

public void setDateTimeFormat(java.lang.String format,
                              java.lang.String language,
                              java.lang.String country)
Sets the date/time format with the given locale.

The format will be based on a locale created from the given language and country arguments.

Parameters:
format - the date/time format
language - the language
country - the country
See Also:
dateTimeFormat

setDateTime

public void setDateTime(boolean enable)
Enables or disables the writting of the date and time information.

Parameters:
enable - true if the date/time info should be written
See Also:
dateTime

setExtendedInfo

public void setExtendedInfo(boolean enable)
Enables or disables the writting of the logging level and facility.

Parameters:
enable - true if the extended info should be written
See Also:
extendedInfo

wouldLog

protected boolean wouldLog(java.lang.String facility,
                           LogLevel level)
Decides whether the logger would log a message with the given loggging level and facility.

It first checks whether the output stream has been initialized and then calls the overriden wouldLog method and returns its result.

Overrides:
wouldLog in class GenericLogger
Parameters:
facility - the logging facility
level - the logging level
Returns:
true if the logger would log the message, false otherwise

write

protected void write(long time,
                     java.lang.String facility,
                     LogLevel level,
                     java.lang.String message,
                     java.lang.Throwable error)
Writes the message to the output stream.

The time argument will be formatted according to the dateTimeFormat field value if writting of the date and time information is enabled via the setDateTime(boolean) method.

Specified by:
write in class GenericLogger
Parameters:
time - the current time of the logged event
facility - the log facility
level - the log level
message - the message
error - the error (optional)
See Also:
GenericLogger.log(String, LogLevel, String), GenericLogger.log(String, LogLevel, String, Throwable)


Copyright (c) 1999-2005, Gnome Ltd. All rights reserved.