Logging Extensions
Project description
Implements a few extensions for the standard python logging library.
Currently, this project lacks documentation. Sorry about that.
Logging Context Filter
Logging Context Filter injects context variables into LogRecord objects as extra fields.
Here’s a usage example:
import logging
import sys
from loggingex.context import LoggingContextFilter, context
log = logging.getLogger()
def process_lines(lines):
for index, line in enumerate(lines):
line = line.strip()
with context(current_line=index + 1):
log.debug("processing line: %s", line)
if not line:
log.error("empty line!")
continue
log.info("processed line: %s", line)
def process_files(filenames):
log.debug("starting...")
for filename in filenames:
with context(current_file=filename):
log.info("processing file: %s", filename)
with open(filename, "r") as f:
process_lines(f)
log.info("processed file: %s", filename)
log.debug("work is complete!")
if __name__ == "__main__":
formatter = logging.Formatter(
"%(current_file)s:%(current_line)s:%(levelname)s: %(message)s"
)
handler = logging.StreamHandler(stream=sys.stdout)
handler.setFormatter(formatter)
handler.setLevel(logging.DEBUG)
handler.addFilter(LoggingContextFilter()) # it's that simple
logging.basicConfig(handlers=[handler], level=logging.DEBUG)
with context(current_file="-", current_line="-"):
# The context above sets default value, so that the formatter does
# not crash, when they are not defined.
process_files(sys.argv[1:])
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
loggingex-1.2.0.tar.gz
(20.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
loggingex-1.2.0-py3-none-any.whl
(11.6 kB
view details)
File details
Details for the file loggingex-1.2.0.tar.gz.
File metadata
- Download URL: loggingex-1.2.0.tar.gz
- Upload date:
- Size: 20.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bdd3bbb9a465f91bcc55c2858a9c6a52ac3918ab1ea2a9aa30002a9ca8c3420a
|
|
| MD5 |
14874e8d14492e891d9a7aece8898906
|
|
| BLAKE2b-256 |
9101bc4cc8eaf8c74a4fca35c26abb60053dfa333e0d22fdf54c964a450d0fe8
|
File details
Details for the file loggingex-1.2.0-py3-none-any.whl.
File metadata
- Download URL: loggingex-1.2.0-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
806fe5c5e134210a894081fedcdf6dace919af62e351f4bfe4c7b2d6aa9c8bdf
|
|
| MD5 |
0e228f29df8b09230749cd3df82e942a
|
|
| BLAKE2b-256 |
8ea91c61e4763a616bdbf11fd0345cfbb0cf9fca327aec7e7e19ebef923217e5
|