pyjld.logger: cross-platform logging utilities
@author: Jean-Lou Dupont
Logger with message look-up and & string.Template functionality
| Parameters: |
|
|---|
The logger must have the following methods:
The :param template_factory: must have a method safe_substitute to render the messages. It defaults to the Template class from the standard string module thus supporting parameters through the escape sequence starting with the $ character eg. $var
A filter entry is a callable which returns a boolean True if the message should be suppressed or False otherwise. Each filter is called in turn with the following parameters:
method_source, object, **kwargs
where method_source is one of [info, debug, warning, critical, error] and object corresponds to the first positional parameter found on the method_source call.
Simple usage
>>> import pyjld.logger
>>> messages = ["msg1":"Message1 [$var]"]
>>> ml = pyjld.logger.MsgLogger("app_name", messages)
>>> ml.info('msg1', var="variable1")
... app_name INFO : Message1 [variable1]
Proxy helper
This class is meant to be private to this module.
Returns a simple cross-platform logger
If a logger with name already exists, its handlers are cleared. This behavior is especially useful in daemon environments where the daemonize process closes open files and the logging facility must be reinitialized.
Usage
>>> log = logger.logger('my_logger')
>>> log.info('message')
Cross-platform syslog handler
| Parameters: |
|
|---|---|
| Return type: | a NTEventLogHandler for win32 platform OR a SysLogHandler for Unix/Linux platforms |
For Unix/Linux platforms, the filesystem path used is as follows
/var/log/$appname.log
The standard SysLogHandler from the logging package is more difficult to configure as it defaults to using the port localhost:514.