The Logger

The Logger is the application developer’s primary interface to using Lithoxyl. It is used to conveniently create Actions and publish them to sinks.

class lithoxyl.logger.Logger(name, sinks=None, **kwargs)[source]

The Logger is one of three core Lithoxyl types, and the main entrypoint to creating Action instances, and publishing those actions to sinks.

Parameters:
  • name (str) – Name of this Logger.
  • sinks (list) – A list of sink objects to be attached to the Logger. Defaults to []. Sinks can be added later with Logger.add_sink().
  • module (str) – Name of the module where the new Logger instance will be stored. Defaults to the module of the caller.

Most Logger methods and attributes fal into three categories: Action creation, Sink registration, and Event handling.

Action creation

The Logger is primarily used through its Action-creating convenience methods named after various log levels: debug(), info(), and critical().

Each creates a new action with a given name, passing any additional keyword arguments on through to the lithoxyl.action.Action constructor.

Logger.debug(action_name, **kw)[source]

Returns a new DEBUG-level Action named name.

Logger.info(action_name, **kw)[source]

Returns a new INFO-level Action named name.

Logger.critical(action_name, **kw)[source]

Returns a new CRITICAL-level Action named name.

The action level can also be passed in:

Logger.action(level, action_name, **kw)[source]

Return a new Action named name classified as level.

Sink registration

Another vital aspect of Loggers is the registration and management of Sinks.

Logger.sinks

A copy of all sinks set on this Logger. Set sinks with Logger.set_sinks().

Logger.add_sink(sink)[source]

Add sink to this Logger’s sinks. Does nothing if sink is already in this Logger’s sinks.

Logger.set_sinks(sinks)[source]

Replace this Logger’s sinks with sinks.

Logger.clear_sinks()[source]

Clear this Logger’s sinks.

Event handling

The event handling portion of the Logger API exists for Logger-Sink interactions.

Logger.on_begin(begin_event)[source]

Publish begin_event to all sinks with on_begin() hooks.

Logger.on_end(end_event)[source]

Publish end_event to all sinks with on_end() hooks.

Logger.on_warn(warn_event)[source]

Publish warn_event to all sinks with on_warn() hooks.

Logger.on_exception(exc_event, exc_type, exc_obj, exc_tb)[source]

Publish exc_event to all sinks with on_exception() hooks.