library for scoped logging on top of structlog (or similar sinks)
Project description
scopedlog
A library for scoped logging on top of structlog (or similar sinks), inspired by the idea of an apparently defunct lithoxyl. Note that I (kshpytsya) have deliberatly not looked into actual lithoxyl's implementation to keep a fresh mind.
Here is an example:
import contextlib import structlog
import structlog.stdlib
import structlog.dev
import structlog.processors
import scopedlog
import scopedlog.sink_structlog
import scopedlog.idgen_seq
structlog.configure(processors=[
structlog.stdlib.add_log_level,
structlog.processors.ExceptionPrettyPrinter(),
structlog.dev.ConsoleRenderer()
])
slog = scopedlog.ScopedLog(
sink=scopedlog.sink_structlog.StructlogSink(structlog.get_logger()),
id_gen=scopedlog.idgen_seq.GlobalSeqScopeIdGenenerator()
)
with contextlib.suppress(RuntimeError):
with slog.info("scope1", k1=1) as sl:
sl.debug("state1", k2=2, k3=3)
sl.info("state1", k4=4)
sl.warn("state1", k5=5)
raise RuntimeError("bad one")
with contextlib.suppress(RuntimeError):
with slog.debug("scope2", k1=1) as sl:
sl.debug("state1", k2=2, k3=3)
sl.info("state1", k4=4)
sl.warn("state1", k5=5)
raise RuntimeError("bad too ;)")
with slog.debug("scope3") as sl:
sl.fail()
with slog.debug("scope4") as sl:
sl.exit_kw["k1"] = 1
And expected output:
See tests for more examples.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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
File details
Details for the file scopedlog-0.1.4.tar.gz.
File metadata
- Download URL: scopedlog-0.1.4.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d32b7c7f572733992d9c3f10a490c45d68d28fc931c8f43c930ad68c23156162
|
|
| MD5 |
4ba0e99b6dc05f216d5c59b5408511ba
|
|
| BLAKE2b-256 |
45df742b6f9554b8b8f56912146c76829a9f2b88bd5daa79dc48c9218e21829a
|
File details
Details for the file scopedlog-0.1.4-py3-none-any.whl.
File metadata
- Download URL: scopedlog-0.1.4-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec0dca83281301af19f2e473a8e883784a027f3d8f541bbd2d3b1b99d8845562
|
|
| MD5 |
06d2ad876135d8131f8b269f66f4896f
|
|
| BLAKE2b-256 |
856c1407050769a205f34828c4115410fa53b9b15971cefa9914715f27837aa6
|