Welcome to pyjld.logger documentation!

pyjld.logger: cross-platform logging utilities

@author: Jean-Lou Dupont

class pyjld.logger.logger.MsgLogger(name, messages, log=None, template_factory=None, filters=None, **kwargs)

Logger with message look-up and & string.Template functionality

Parameters:
  • name – the logger name
  • messages – the message look-up dictionary
  • log – an optional logger (instead of the default one)
  • template_factory – a template factory for handling the messages
  • filters – a list of callable filters
  • kwargs – keyword parameters to pass to the __init__ method of the logger

The logger must have the following methods:

  • info
  • debug
  • warning
  • error
  • critical

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]

Auto-Flush

Once a message is logged, all handlers are visited and flushed. Each handler is inspected for the flush method thus only supported handlers are flushed.

addFilter(filter_callable)
Appends a filter to the current list
addFilters(filters)
Configures the filter list
flush()
Performs a flush on each handler that supports it
getMessageId
Tries to retrieve a message_id from the object. If successful, the said identifier can be used for template based substitution as well as for the filtering functionality.
removeFilters()
Removes all filters
class pyjld.logger.logger.Proxy(source, target)

Proxy helper

This class is meant to be private to this module.

pyjld.logger.logger.logger(name, include_console=False, include_syslog=False, formatter=None, console_stream=None)

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')
pyjld.logger.logger.xcLogger(appname)

Cross-platform syslog handler

Parameters:
  • appname (string) – the application name to log messages against
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.

Indices and tables

Table Of Contents

This Page

Quick search