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:])
Release files for loggingex 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| loggingex-1.2.0.tar.gz | 20.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| loggingex-1.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 32.4 kB
Release files / loggingex-1.2.0.tar.gz
| Download URL | loggingex-1.2.0.tar.gz |
|---|---|
| Size | 20.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bdd3bbb9a465f91bcc55c2858a9c6a52ac3918ab1ea2a9aa30002a9ca8c3420a
|
|
BLAKE2b-256 checksum How to use checksums |
9101bc4cc8eaf8c74a4fca35c26abb60053dfa333e0d22fdf54c964a450d0fe8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / loggingex-1.2.0-py3-none-any.whl
| Download URL | loggingex-1.2.0-py3-none-any.whl |
|---|---|
| Size | 11.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
806fe5c5e134210a894081fedcdf6dace919af62e351f4bfe4c7b2d6aa9c8bdf
|
|
BLAKE2b-256 checksum How to use checksums |
8ea91c61e4763a616bdbf11fd0345cfbb0cf9fca327aec7e7e19ebef923217e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|