com.samskivert.util
Class Log

java.lang.Object
  extended by com.samskivert.util.Log

public final class Log
extends Object

The log services provide debug, info and warning message logging capabilities for a set of modules. These log services are designed to provide the basic functionality needed by the samskivert codebase. It is expected that the LogProvider interface will be used to map these log services onto whatever more general purpose logging framework is in use by the user of the samskivert codebase.

The log provider can be set via a system property to ensure that it is in effect as soon as the log services are used. When invoking your JVM, specify -Dlog_provider=classname and it will automatically be instantiated and put into effect by the log services. If your log provider needs more sophisticated configuration, you'll have to instantiate it yourself and set it using setLogProvider(com.samskivert.util.LogProvider).


Field Summary
protected  String _moduleName
          The name of the module to which this log instance is associated.
protected static LogProvider _provider
          The log provider currently in use by the log services.
static int DEBUG
          Log level constant for debug entries.
static int INFO
          Log level constant for info entries.
static int WARNING
          Log level constant for warning entries.
 
Constructor Summary
Log(String moduleName)
          Constructs a new log object with the supplied module name.
 
Method Summary
 void debug(String message)
          Logs the specified message at the debug level if such messages are enabled.
static int getLevel()
          Returns the default log level for all modules.
static int getLevel(String moduleName)
          Returns the log level of the specified module.
static LogProvider getLogProvider()
          Returns the log provider currently in use by the logging services.
protected static void inferConfiguration()
          Checks the log_provider system property to see if a log provider has been specified.
 void info(String message)
          Logs the specified message at the info level if such messages are enabled.
static int levelFromString(String level)
          Returns the log level that matches the specified string or -1 if the string could not be interpretted as a log level.
static String levelToString(int level)
          Returns a string representation of the specified log level.
 void logStackTrace(int level, Throwable t)
          Logs the stack trace of the supplied throwable at the specified level (if the current log level for this module is at or below the specified level).
static void setLevel(int level)
          Sets the log level for all modules to the specified level.
static void setLevel(String moduleName, int level)
          Sets the log level of the specified module to the specified value.
static void setLogProvider(LogProvider provider)
          Instructs the logging services to use the specified log provider to perform the actual logging.
 void warning(String message)
          Logs the specified message at the warning level if such messages are enabled.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public static final int DEBUG
Log level constant for debug entries.

See Also:
Constant Field Values

INFO

public static final int INFO
Log level constant for info entries.

See Also:
Constant Field Values

WARNING

public static final int WARNING
Log level constant for warning entries.

See Also:
Constant Field Values

_moduleName

protected String _moduleName
The name of the module to which this log instance is associated.


_provider

protected static LogProvider _provider
The log provider currently in use by the log services.

Constructor Detail

Log

public Log(String moduleName)
Constructs a new log object with the supplied module name.

Method Detail

debug

public void debug(String message)
Logs the specified message at the debug level if such messages are enabled.


info

public void info(String message)
Logs the specified message at the info level if such messages are enabled.


warning

public void warning(String message)
Logs the specified message at the warning level if such messages are enabled.


logStackTrace

public void logStackTrace(int level,
                          Throwable t)
Logs the stack trace of the supplied throwable at the specified level (if the current log level for this module is at or below the specified level).


setLevel

public static void setLevel(String moduleName,
                            int level)
Sets the log level of the specified module to the specified value. The log level indicates which messages are logged and which are not. For example, if the level was set to warning, then only warning and error messages would be logged because info and debug messages have a 'lower' log level.

Note: the log provider implementation may choose to propagate the supplied level to all modules that are contained by this module in the module hierarchy. For example, setting the "swing.util" module to debug could also set the "swing.util.TaskMaster" level to debug because it is contained by the specified module.


setLevel

public static void setLevel(int level)
Sets the log level for all modules to the specified level.


getLevel

public static int getLevel(String moduleName)
Returns the log level of the specified module.


getLevel

public static int getLevel()
Returns the default log level for all modules.


getLogProvider

public static LogProvider getLogProvider()
Returns the log provider currently in use by the logging services.


setLogProvider

public static void setLogProvider(LogProvider provider)
Instructs the logging services to use the specified log provider to perform the actual logging.


levelFromString

public static int levelFromString(String level)
Returns the log level that matches the specified string or -1 if the string could not be interpretted as a log level.


levelToString

public static String levelToString(int level)
Returns a string representation of the specified log level.


inferConfiguration

protected static void inferConfiguration()
Checks the log_provider system property to see if a log provider has been specified. Installs it if so. Checks the log_level system property to see if a default log level has been specified. Sets it if so.



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