loggers - Logging made Easy

This module complements the python logging module. It is designed to seamlessly integrate with other logging libraries. Behind the scenes, loggers adds buffering handlers to each new logger it creates, to allow for logging before the logging interface is configured. For simple logging scripts, try getSimpleLogger().

Logger Functions

pyshell.loggers.configure_logging(configuration)[source]

Setup logging from a configuration object. Configuration should meet Python’s logging.config configuration requirements. This method uses logging.config.dictConfig() to process configurations.

Parameters:configuration – Any object which can be interpreted by pyshell.config.DottedConfiguration.make().

The loggers will be configured. If any loggers to be configured have a BufferHandler, that buffer will be emptied into the newly configured handlers.

pyshell.loggers.getLogger(name=None)[source]

Return a logger for a specified name.

This differs from the built-in logging.getLogger() function as it ensures that returned loggers will have a BufferHandler attached if no other handlers are found. It can be otherwise used in place of logging.getLogger().

pyshell.loggers.getSimpleLogger(name=None, level=None)[source]

Retrieves a logger with a simple logging configuration setup, which writes colorful logging output to the console using the configuration provided by logging-stream-all.yml. Only the root logger is configured with the console handler, all others have only a level set.

Parameters:
  • name – The logger name to be returned (like in getLogger()).
  • level – The level of the configured logger.

Configurations are cumulative, so getSimpleLogger() can be called multiple times.

pyshell.loggers.debuffer_logger(name=None)[source]

Debuffer a given logger.

Parameters:name – The name of the logger to debuffer.

This method will atempt to dump all of the messages from a logger’s BufferHandler into its other handlers. Then it will remove the buffer from the logger.

pyshell.loggers.buffer_logger(name=None)[source]

Buffer named logger.

Parameters:name – The name of the logger to debuffer.

This method will add a BufferHandler to the named logger, and will remove the other handlers.

class pyshell.loggers.ManyTargetHandler(capacity, flushLevel=40, target=None, targets=None)[source]

A new default handler (similar to a NULL handler) which holds onto targets for later.

setTarget(target)[source]

Add another target to the handler

flush()[source]

Flush out this handler

close()[source]

Close the handler

class pyshell.loggers.BufferHandler(capacity, flushLevel=40, target=None, targets=None)[source]

A special case of ManyTargetHandler for use with debuffer_logger().

class pyshell.loggers.ColorStreamFormatter(fmt=None, datefmt=None)[source]

Print to stream with colors!

format(record)[source]

Format a record with colors from the terminal module.

Table Of Contents

Previous topic

config — YAML-based Configuration Dictionaries

Next topic

util - Utilities

This Page