org.iges.anagram
Class Log

java.lang.Object
  |
  +--org.iges.anagram.Log
All Implemented Interfaces:
Module

public class Log
extends java.lang.Object
implements Module

Provides logging services for the server.


Nested Class Summary
protected  class Log.Rotater
          Produces rotating filenames either monthly, weekly, or daily.
 
Field Summary
protected static int CONSOLE_MODE
          Mode for log output
static int CRITICAL
          Level of log output
protected  java.lang.String dateTemplate
           
static int DEBUG
          Level of log output
protected  int defaultLevel
           
protected  java.text.DateFormat entryFormat
           
static int ERROR
          Level of log output
protected static int FILE_MODE
          Mode for log output
static int INFO
          Level of log output
static java.lang.String[] LEVEL_NAME
          Name associated with each level.
protected  java.lang.String logFileName
           
protected  java.io.PrintWriter logWriter
           
protected  int mode
           
protected static java.lang.String[] MODE_NAME
          Name associated with each log mode.
protected  java.lang.String moduleName
           
protected  java.util.Map moduleSettings
           
static int NUM_LEVELS
           
protected  java.text.FieldPosition pos
           
protected  boolean printMem
           
protected  boolean printModule
           
protected static int ROTATE_MODE
          Mode for log output
protected  Log.Rotater rotater
           
protected  Server server
           
static int SILENT
          Level of log output
static int VERBOSE
          Level of log output
 
Constructor Summary
Log()
           
 
Method Summary
 void configure(Setting setting)
          Configures the module according to the settings provided.
protected  void consoleMode()
          Directs log output to the console (stderr).
 void critical(Module module, java.lang.String message)
          Writes a critical error message to the current log output.
 void debug(Module module, java.lang.String message)
          Writes a debug message to the current log output.
 boolean enabled(int level, Module module)
          Returns true if logging detail is set to the given level or higher for the specified module.
 void error(Module module, java.lang.String message)
          Writes an error message to the current log output.
static int getLevel(java.lang.String levelName)
          Translates a given log level name into an integer constant.
protected static int getMode(java.lang.String modeName)
          Translates a given log level name into an integer constant.
 java.lang.String getModuleID()
          Returns an ID for this module.
 java.lang.String getModuleName()
          Returns the complete name of the module, including parents.
 void info(Module module, java.lang.String message)
          Writes an info message to the current log output.
 void init(Server server, Module parent)
          Initializes the module.
 void log(int level, Module module, java.lang.String message)
          Writes a message to the current log output.
protected  void open(java.lang.String filename)
          Directs log output to the filename given.
protected  void parseLevel(Setting setting)
          Sets flags for what messages should be printed
protected  void parseMode(Setting setting)
          Sets the log mode to console, file, or rotating.
protected  void parseModuleSettings(Setting setting)
          Sets up per-module logging configuration
 void verbose(Module module, java.lang.String message)
          Writes a verbose message to the current log output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

server

protected Server server

defaultLevel

protected int defaultLevel

mode

protected int mode

printMem

protected boolean printMem

printModule

protected boolean printModule

dateTemplate

protected java.lang.String dateTemplate

entryFormat

protected java.text.DateFormat entryFormat

pos

protected java.text.FieldPosition pos

logFileName

protected java.lang.String logFileName

rotater

protected Log.Rotater rotater

logWriter

protected java.io.PrintWriter logWriter

moduleName

protected java.lang.String moduleName

moduleSettings

protected java.util.Map moduleSettings

DEBUG

public static final int DEBUG
Level of log output

See Also:
Constant Field Values

VERBOSE

public static final int VERBOSE
Level of log output

See Also:
Constant Field Values

INFO

public static final int INFO
Level of log output

See Also:
Constant Field Values

ERROR

public static final int ERROR
Level of log output

See Also:
Constant Field Values

CRITICAL

public static final int CRITICAL
Level of log output

See Also:
Constant Field Values

SILENT

public static final int SILENT
Level of log output

See Also:
Constant Field Values

NUM_LEVELS

public static final int NUM_LEVELS
See Also:
Constant Field Values

LEVEL_NAME

public static final java.lang.String[] LEVEL_NAME
Name associated with each level. Matches integer constant list above.


CONSOLE_MODE

protected static final int CONSOLE_MODE
Mode for log output

See Also:
Constant Field Values

FILE_MODE

protected static final int FILE_MODE
Mode for log output

See Also:
Constant Field Values

ROTATE_MODE

protected static final int ROTATE_MODE
Mode for log output

See Also:
Constant Field Values

MODE_NAME

protected static final java.lang.String[] MODE_NAME
Name associated with each log mode. Matches integer constant list above.

Constructor Detail

Log

public Log()
Method Detail

getModuleID

public final java.lang.String getModuleID()
Description copied from interface: Module
Returns an ID for this module. This ID should be a legal XML tag name. It has two uses: as a tag name in the server's configuration file, and as the final element of the complete module name.

Specified by:
getModuleID in interface Module

getModuleName

public final java.lang.String getModuleName()
Description copied from interface: Module
Returns the complete name of the module, including parents. The syntax is: complete_name : [parents] module_id
parents : [parents] parent '/'
The complete module name is used as an identifier in log messages.

Specified by:
getModuleName in interface Module

init

public final void init(Server server,
                       Module parent)
Description copied from interface: Module
Initializes the module.

This method should copy the server and parent references provided to internal fields, so that the module has access to the rest of the module hierarchy, and then call the init() method of any sub-modules. It can also be used to perform any one-time initialization that requires access to other modules.

This method will only be called once, immediately after the module is created, and before it is configured for the first time. Thus it does not need to be thread-safe.

Specified by:
init in interface Module

configure

public void configure(Setting setting)
               throws ConfigException
Description copied from interface: Module
Configures the module according to the settings provided.

This method is guaranteed to be called at least once before any requests are sent to the module. The server supports dynamic reconfiguration, and thus this method may be called any number of times during the life of the module. However, it is guaranteed that this method will never be called while a servlet request is being processed. Thus it does not need to be thread-safe.

If this module contains other modules, it is responsible for configuring them using the appropriate sub-settings. Each module should receive the sub-setting that matches its module ID, so that the XML tags in the configuration file match up with the module names in the log file.

Specified by:
configure in interface Module
Throws:
ConfigException - If the module is unable to operate using the settings provided. This will halt the server's operation, and thus should only be thrown if there is no reasonable default that can be used in place of a missing or invalid setting.

log

public void log(int level,
                Module module,
                java.lang.String message)
Writes a message to the current log output.

Critical error messages are prefaced with the string "CRITICAL: ". Error messages are prefaced with the string "error: ". Debug messages are prefaced with the string "*dbg* ". All other messages are written as is.

Parameters:
level - The level of message - debug, verbose, info, error, or critical
module - The module that is generating the message
message - The message itself.

critical

public void critical(Module module,
                     java.lang.String message)
Writes a critical error message to the current log output.

Parameters:
module - The module that is generating the message
message - The message itself.

error

public void error(Module module,
                  java.lang.String message)
Writes an error message to the current log output.

Parameters:
module - The module that is generating the message
message - The message itself.

info

public void info(Module module,
                 java.lang.String message)
Writes an info message to the current log output.

Parameters:
module - The module that is generating the message
message - The message itself.

verbose

public void verbose(Module module,
                    java.lang.String message)
Writes a verbose message to the current log output.

Parameters:
module - The module that is generating the message
message - The message itself.

debug

public void debug(Module module,
                  java.lang.String message)
Writes a debug message to the current log output.

Parameters:
module - The module that is generating the message
message - The message itself.

enabled

public boolean enabled(int level,
                       Module module)
Returns true if logging detail is set to the given level or higher for the specified module.


parseLevel

protected void parseLevel(Setting setting)
Sets flags for what messages should be printed


parseMode

protected void parseMode(Setting setting)
                  throws ConfigException
Sets the log mode to console, file, or rotating.

ConfigException

parseModuleSettings

protected void parseModuleSettings(Setting setting)
Sets up per-module logging configuration


open

protected void open(java.lang.String filename)
Directs log output to the filename given.


consoleMode

protected void consoleMode()
Directs log output to the console (stderr).


getLevel

public static final int getLevel(java.lang.String levelName)
Translates a given log level name into an integer constant.


getMode

protected static final int getMode(java.lang.String modeName)
Translates a given log level name into an integer constant.