Skip to main content

Python logging, configured the way I like it.

Project description

Python logging, configured the way I like it.

Logger Behavior

Default behavior when using lo99ing:

  • logs to stderr only
  • log level (of each individual logger) defaults to:
  • WARNING for “installed” modules (site-packages and dist-packages)
  • INFO for “local” modules (in user’s local dev env)
  • message format: %(asctime)s:%(levelname)s:%(name)s: %(message)s

Message Logging Behavior

  • logger.exception() automatically extracts and prints exception attributes
  • When logging an exception object, automatically adds exception type:
  • logger.error('exception raised: %s', KeyError(0))  # prints: 'exception raised: KeyError -- 0'
  • if logging messages fails formatting, also logs the location of the problematic call:
  •'forgot the percent sign', 555)  # includes: 'Logged from /path/to/'

Usage and Other Features

  • Get a logger using get_logger(logger_name, ...)
  • Get a logger with current module’s (or script’s) basename using: get_logger(__file__)
  • Log to a file, using enable_file(filename)
  • Create an “independent” (i.e., propagate=False) file-logger, using get_file_logger(filename)
  • Disable/re-enable logging to stderr (on root logger), using enable_stderr() and disable_stderr()
  • Change logging clock “converter” to UTC using use_utc()
  • Change logging clock to a custom clock using use_clock(clock)
  • This is useful when “replaying past events”, and you want timestamps to appear accordingly
  • log-level overrides: set and reset (“undo”) log levels using overrides:
  • logger.set_log_level_override(level) or set_log_level_override(name, level),
  • reset using set_log_level_override(name, None)
  • Create a logger-like object, which adds a prefix to messages it logs, using logger.prefixed('PREFIX:')
  • Log a “trace” message with current filename and line number, using logger.TRACE()
  • useful for “tracing” / “printf-debugging”

Usage Notes

  • Should avoid using logging.getLogger() directly. Instead, use lo99ing.get_logger()
  • Should not use logger.setLevel() directly. Instead, use get_logger(..., level=LEVEL, ...) or set_log_level_override()


Using pip:

pip install lo99ing

Project details

Download files

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

Files for lo99ing, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size lo99ing-0.1.1.tar.gz (9.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page