Skip to main content

Logging extension to emit full logs when a threshold is reached

Project description

pastlogging — Logging extension for Python

Source code: https://github.com/jimstraus/pastlogging

This module extends the built in logging module in Python. It supports both Python 2.3 and greater and Python 3.X.

The key benefit is to provide a mechanism where logs are not cluttered with info and debug messages, but when a warning or error occurs, you get all the previous info and debug messages. Because it is based on the standard logging module, all the usual flexibility in terms of handlers, filters, name spaces, etc. are available.

Please read the Python Standard Library documentation for logging to understand all the normal options and mechanisms for logging.

PastLogger Objects

PastLoggers are extended with the following methods. Not that PastLoggers are generated and retrieved using the same mechanism as the normal logger.

logging.getLogger()

PastLogger.setLevel(level)

Sets the threshold for this logger to level. Logging messages which are less severe than level will be held (up to a maximum number, see below). If a message equals or is greater than the threshold, then all held messages and the current message are sent to the log(s).

PastLogger.setMinLevel(level)

Sets the minimum level of messages to be held. No messages below the minimum level will be held.

PastLogger.setMax(number)

Sets the number of messages to be held. The default is 1000 and if set to -1 there is no limit.

PastLogger.reset()

Resets the buffer holding messages. This can be used when entering code where the previous operations completed either successfully or unsuccessfully.

PastLogger Usage

To minimize the changes to existing code, you may

import pastlogging as logging

At that point, all code using logging should work as expected.

Since the previous log messages are sent to the logs at the same time, the timestamp stored in the LogRecords themselves. This can be configured using

logging.basicConfig(format='%(asctime)s %(message)s')

Or see the builtin logging documentation for further formatting optinos.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pastlogging-1.0a1.tar.gz (6.0 kB view hashes)

Uploaded Source

Built Distribution

pastlogging-1.0a1-py3-none-any.whl (6.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page