chapps.logging module

Logging

This module’s purpose is to ensure that CHAPPS modules end up instantiating loggers which all share a common formatter and handler.

It has been reworked a little bit since its inception, and it may approach the issue from two directions, still. It does attempt to be the first thing to get a handler, and thereby be able to set the basic config.

But it also instantiates a logger at the top of the hierarchy, one named simply chapps, so that all further CHAPPS loggers (using the recommended pattern) will be under that parent logger and inherit its config.

chapps.logging.DEFAULT_LEVEL = 10

Default minimum severity DEBUG

chapps.logging.DEFAULT_FACILITY = 16

Default syslog facility LOCAL0

class chapps.logging.LogSetup[source]

Bases: object

Establish global log format and handler for CHAPPS

For consistency, logs from different modules should all appear to come from CHAPPS, otherwise it may be quite a headache to make sense of them. The class defines two different formatters, one for debugging and one for general use. There is no fancy method in place for switching between them at present.

The default formatter is very basic, simply prepending “CHAPPS:” and the severity level to the message.

The default minimum severity at present is DEBUG.

The default syslog facility is LOCAL0.

It is possible to use rsyslog configuration to send different levels of the LOCAL0 facility to different destinations, or to ignore DEBUG level messages entirely. An example config is included in the project’s ancillary materials.

It had been a conscious decision not to include the chapps.config module in this module, in order to avoid circular dependencies when this module was included everywhere. The rework has the config module loaded as part of package initialization, so it is no longer necessary to load it anywhere, since once it is loaded its job is done.

debug_formatter = <logging.Formatter object>

A formatter helpful for debugging.

maillog_formatter = <logging.Formatter object>

The default formatter, anticipated to go to the mail log

syslog_handler = <SysLogHandler (DEBUG)>

A handler which uses /dev/log to send messages to syslog

__init__()[source]

Setup logging

If there are not yet any handlers, this routine calls logging.basicConfig() to set up basic logging configuration.

If there are already handlers, for instance due to running within pytest, then nothing happens.

chapps.logging.logger = <Logger chapps (DEBUG)>

Create a logger in order to configure the top of the hierarchy