com.samskivert.util
Class DefaultLogProvider

java.lang.Object
  extended by com.samskivert.util.DefaultLogProvider
All Implemented Interfaces:
LogProvider

public class DefaultLogProvider
extends Object
implements LogProvider

If no log provider is registered with the log services, the default provider will be used. The default provider simply logs messages to System.err and manages log levels in a simplistic way.

See Also:
Log, LogProvider

Field Summary
protected  SimpleDateFormat _format
          Used to accompany log messages with time stamps.
protected  FieldPosition _fpos
          Needed for the more efficient SimpleDateFormat.format(Date,StringBuffer,FieldPosition).
protected  int _level
          The default log level.
protected  HashMap<String,Integer> _levels
          The levels of each module.
protected static Dimension _tdimens
          Contains the dimensions of the terminal window in which we're running, if it was possible to obtain them.
protected  boolean _useVT100
          Whether or not to use the vt100 escape codes.
protected  boolean _wrapLog
          Whether or not to wrap the log lines.
protected static String GAP
          Used to align wrapped log lines.
protected static String[] LEVEL_CHARS
          Used to tag log messages with their log level.
 
Constructor Summary
DefaultLogProvider()
          Constructs a default log provider.
 
Method Summary
protected  String formatEntry(String moduleName, int level, String message)
           
 int getLevel()
          Returns the default log level for all modules.
 int getLevel(String moduleName)
          Returns the log level for the specified module.
 void log(int level, String moduleName, String message)
          Log a message at the specified level for the specified module, if messages are enabled for that particular combination.
 void logStackTrace(int level, String moduleName, Throwable t)
          Log the stack trace of the supplied throwable at the specified level for the specified module, if messages are enabled for that particular combination.
protected static void obtainTermSize()
          Attempts to obtain the dimensions of the terminal window in which we're running.
 void setLevel(int level)
          Set the log level for all modules to the specified level.
 void setLevel(String moduleName, int level)
          Set the log level for the specified module to the specified level.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_level

protected int _level
The default log level.


_levels

protected HashMap<String,Integer> _levels
The levels of each module.


_format

protected SimpleDateFormat _format
Used to accompany log messages with time stamps.


_fpos

protected FieldPosition _fpos
Needed for the more efficient SimpleDateFormat.format(Date,StringBuffer,FieldPosition).


_tdimens

protected static Dimension _tdimens
Contains the dimensions of the terminal window in which we're running, if it was possible to obtain them. Otherwise, it contains the default dimensions. This is used to wrap lines.


_useVT100

protected boolean _useVT100
Whether or not to use the vt100 escape codes.


_wrapLog

protected boolean _wrapLog
Whether or not to wrap the log lines.


LEVEL_CHARS

protected static final String[] LEVEL_CHARS
Used to tag log messages with their log level.


GAP

protected static final String GAP
Used to align wrapped log lines.

See Also:
Constant Field Values
Constructor Detail

DefaultLogProvider

public DefaultLogProvider()
Constructs a default log provider.

Method Detail

log

public void log(int level,
                String moduleName,
                String message)
Description copied from interface: LogProvider
Log a message at the specified level for the specified module, if messages are enabled for that particular combination.

Specified by:
log in interface LogProvider

logStackTrace

public void logStackTrace(int level,
                          String moduleName,
                          Throwable t)
Description copied from interface: LogProvider
Log the stack trace of the supplied throwable at the specified level for the specified module, if messages are enabled for that particular combination.

Specified by:
logStackTrace in interface LogProvider

setLevel

public void setLevel(String moduleName,
                     int level)
Description copied from interface: LogProvider
Set the log level for the specified module to the specified level. The log services assume that all messages at or higher than the specified level will be logged.

Specified by:
setLevel in interface LogProvider

setLevel

public void setLevel(int level)
Description copied from interface: LogProvider
Set the log level for all modules to the specified level. The log services assume that all messages at or higher than the specified level will be logged.

Specified by:
setLevel in interface LogProvider

getLevel

public int getLevel(String moduleName)
Description copied from interface: LogProvider
Returns the log level for the specified module.

Specified by:
getLevel in interface LogProvider

getLevel

public int getLevel()
Description copied from interface: LogProvider
Returns the default log level for all modules.

Specified by:
getLevel in interface LogProvider

formatEntry

protected String formatEntry(String moduleName,
                             int level,
                             String message)

obtainTermSize

protected static void obtainTermSize()
Attempts to obtain the dimensions of the terminal window in which we're running. This is extremely platform specific, but feel free to add code to do the right thing for your platform.



Copyright © 2000-2008 Michael Bayne. All Rights Reserved.