Created a thin wrapper through which we can log to an arbitrary logging

framework.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@15 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2000-12-06 00:24:46 +00:00
parent 558cefb280
commit d2a43bc589
3 changed files with 129 additions and 1 deletions
@@ -0,0 +1,94 @@
//
// $Id: Log.java,v 1.1 2000/12/06 00:24:46 mdb Exp $
package com.samskivert.util;
/**
* 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 <code>LogProvider</code> 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.
*/
public final class Log
{
/** Log level constant for debug entries. */
public static final int DEBUG = 0;
/** Log level constant for info entries. */
public static final int INFO = 0;
/** Log level constant for warning entries. */
public static final int WARNING = 0;
/**
* Constructs a new log object with the supplied module name.
*/
public Log (String moduleName)
{
_moduleName = moduleName;
}
/**
* Logs the specified message at the debug level if such messages are
* enabled.
*/
public void debug (String message)
{
_provider.log(DEBUG, _moduleName, message);
}
/**
* Logs the specified message at the info level if such messages are
* enabled.
*/
public void info (String message)
{
_provider.log(INFO, _moduleName, message);
}
/**
* Logs the specified message at the warning level if such messages
* are enabled.
*/
public void warning (String message)
{
_provider.log(WARNING, _moduleName, message);
}
/**
* 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.
*
* <p/> 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.
*/
public static void setLevel (String moduleName, int level)
{
_provider.setLevel(moduleName, level);
}
/**
* Sets the log level for all modules to the specified level.
*/
public static void setLevel (int level)
{
_provider.setLevel(level);
}
public static void setLogProvider (LogProvider provider)
{
_provider = provider;
}
protected String _moduleName;
protected static LogProvider _provider;
}
@@ -0,0 +1,32 @@
//
// $Id: LogProvider.java,v 1.1 2000/12/06 00:24:46 mdb Exp $
package com.samskivert.util;
/**
* The log provider interface allows the simple logging services provided
* to the samskivert codebase to be mapped onto an actual logging
* framework.
*/
public interface LogProvider
{
/**
* Log a message at the specified level for the specified module, if
* messages are enabled for that particular combination.
*/
public void log (int level, String moduleName, String message);
/**
* 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.
*/
public void setLevel (String moduleName, int level);
/**
* 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.
*/
public void setLevel (int level);
}
@@ -1,9 +1,11 @@
#
# $Id: Makefile,v 1.2 2000/10/31 00:48:13 mdb Exp $
# $Id: Makefile,v 1.3 2000/12/06 00:24:46 mdb Exp $
ROOT = ../../..
SRCS = \
Log.java \
LogProvider.java \
PropertiesUtil.java \
StringUtil.java \