Skip to main content

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:

  • logger.info('forgot the percent sign', 555) # includes: 'Logged from /path/to/file.py:LINENUM'

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()

Installation

Using pip:

pip install lo99ing

Metadata

Release files for lo99ing 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lo99ing 0.1.4
File Size Uploaded
lo99ing-0.1.4.tar.gz 11.2 kB Details

Release files / lo99ing-0.1.4.tar.gz

Download URL lo99ing-0.1.4.tar.gz
Size 11.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c68cc6560556a7ad9aaafbc28897ec1ae5ba1d6230550dfaa77477d272ef05ed
BLAKE2b-256 checksum
How to use checksums
af4f58c1c54c46383f8aff3b448ffa5cd1d19a33a5ba52799a041feb1fd8ce55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release history Release notifications | RSS feed

This release

0.1.4 This release

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page