public class LoggingModule extends AbstractModule
A module that provides logging facilities for other modules. Logging modules should follow a slightly different life cycle to other modules. This is because logging might be needed already in the init or getDependencies phase of modules while module functions typically become available only after the module has been started. You should initialise the logging into a state where it can be fully used already in the init method.
This default implementation supports two initialisation parameters. First parameter is "log", you can use this to specify the logging mechanism that should be used. This should be an instance of org.apache.commons.logging.Log. If not specified, the logger of the module manager is used, and if that is not specified either, a SimpleLog is created which outputs messages to stderr.
You may use the logLevel initialisation parameter to set the lowest level of logging messages that are printed. Messages of lower level than this are simple ignored. The possible values for this are trace, debug, info, warn, error, fatal and none. None is used to suppress logging entirely while providing a logging module for other modules that require it. The default log level is trace, i.e. all logging messages are printed. However, bear in mind that the underlying logger may have its own mechanisms to further filter logging messages. Thus even if this LoggingModule is set to print all messages, the logging level may be filtered to a higher level elsewhere. This is dependent on the logging implementation used.
Modifier and Type | Class and Description |
---|---|
static class |
LoggingModule.SubLog |
Modifier and Type | Field and Description |
---|---|
protected org.apache.commons.logging.Log |
log |
protected int |
logLevel |
autoStart, isInitialized, isRunning, logging, loggingModule, moduleManager
Constructor and Description |
---|
LoggingModule() |
LoggingModule(org.apache.commons.logging.Log log) |
Modifier and Type | Method and Description |
---|---|
org.apache.commons.logging.Log |
getLog() |
org.apache.commons.logging.Log |
getLog(Module module) |
org.apache.commons.logging.Log |
getLog(java.lang.String moduleName) |
static org.apache.commons.logging.Log |
getLog(java.lang.String moduleName,
org.apache.commons.logging.Log log) |
int |
getLogLevel() |
void |
init(ModuleManager manager,
java.util.HashMap<java.lang.String,java.lang.Object> settings)
Initialises the module.
|
getDependencies, isInitialized, isRunning, requireLogging, start, stop, toString
public LoggingModule()
public LoggingModule(org.apache.commons.logging.Log log)
public org.apache.commons.logging.Log getLog()
public org.apache.commons.logging.Log getLog(Module module)
public org.apache.commons.logging.Log getLog(java.lang.String moduleName)
public static org.apache.commons.logging.Log getLog(java.lang.String moduleName, org.apache.commons.logging.Log log)
public int getLogLevel()
public void init(ModuleManager manager, java.util.HashMap<java.lang.String,java.lang.Object> settings) throws ModuleException
Module
Initialises the module. After constructor, this is the first method called in the life cycle of a module. It should not perform anything time consuming or anything with notable outside side effects. It should only read the parameters and initialise the module so that it can later be started. Note that a module being initialised doesn't mean that it necessarily will ever be started.
A ModuleException may be thrown if something vital is missing from the parameters or they are not sensible. In some cases you may not want to throw an exception even if vital initialisation information is missing. If, for example, it is possible that the module is initialised in some other way between the init and the start method calls. A ModuleException may also be thrown at the start method if the module is still not initialised.
init
in interface Module
init
in class AbstractModule
manager
- The module manager handling this module. You may keep a
reference to it if needed.ModuleException
Copyright 2004-2015 Wandora Team