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, **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
  • pargs – positional parameters to pass to the __init__ method of the logger
  • kwargs – keyword parameters to pass to the __init__ method of the logger

The logger must have the following methods:

  • info
  • debug
  • warning
  • 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

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]
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

Usage

>>> log = logger.logger('my_logger')
>>> log.info('message')
pyjld.logger.logger.xcLogger(appname)

Cross-platform syslog handler

  • Returns a NTEventLogHandler for win32 platform
  • Returns 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