loggingx.py
loggingx is a drop-in replacement for Python's built-in logging module. Even better, once you've imported loggingx, you don't need to modify your existing logging module.
python3 -m pip install loggingx-py
Additional Format
| Attribute name | Format | Description |
|---|---|---|
| caller | %(caller)s | Caller(<pathname>:<lineno>) |
| ctxFields | %(ctxFields)s | Context fields |
Optimization
| Configuration | Description |
|---|---|
logging.logThreads |
If False, Record will not collect thread and threadName. |
logging.logProcesses |
If False, Record will not collect process. |
logging.logMultiprocessing |
If False, Record will not collect processName. |
Context
import loggingx as logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s\t%(levelname)s\t%(caller)s\t%(message)s\t%(ctxFields)s",
)
def A() -> None:
logging.info("A")
with logging.addFields(A="a"):
B()
def B() -> None:
logging.info("B")
with logging.addFields(B="b"):
C()
def C() -> None:
logging.info("C")
if __name__ == "__main__":
A()
2023-07-19 01:15:33,981 INFO loggingx.py/main.py:10 A {}
2023-07-19 01:15:33,981 INFO loggingx.py/main.py:16 B {'A': 'a'}
2023-07-19 01:15:33,982 INFO loggingx.py/main.py:22 C {'A': 'a', 'B': 'b'}
JSONFormatter
import loggingx as logging
handler = logging.StreamHandler()
handler.setFormatter(logging.JSONFormatter())
logging.basicConfig(level=logging.INFO, handlers=[handler])
if __name__ == "__main__":
with logging.addFields(ctx="ctx"):
logging.info("test", extra={"extra": "extra"})
{"time": 1689697694.9980711, "level": "info", "caller": "loggingx.py/main.py:9", "msg": "test", "ctx": "ctx", "extra": "extra"}
With logging
import logging
import loggingx
# handler = loggingx.StreamHandler()
handler = logging.StreamHandler()
handler.setFormatter(loggingx.JSONFormatter())
# loggingx.basicConfig(level=loggingx.INFO, handlers=[handler])
logging.basicConfig(level=logging.INFO, handlers=[handler])
if __name__ == "__main__":
with loggingx.addFields(ctx="ctx"):
# loggingx.info("test", extra={"extra": "extra"})
logging.info("test", extra={"extra": "extra"})
jq
alias log2jq="jq -R -r '. as \$line | try fromjson catch \$line'"
python3 <path> 2>&1 | log2jq
Metadata
Release files for loggingx-py 0.5.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 | Provenance | Actions |
|---|---|---|---|---|
| loggingx-py-0.5.0.tar.gz | 39.8 kB | Without provenance | Details for loggingx-py-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| loggingx_py-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for loggingx_py-0.5.0-py3-none-any.whl |
Total release size: 46.1 kB
Release files / loggingx-py-0.5.0.tar.gz
| Download URL | loggingx-py-0.5.0.tar.gz |
|---|---|
| Size | 39.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
84b4798dd090f271ebfb329927efaf00daa628d18c508278dcd668fefe78db18
|
|
BLAKE2b-256 checksum How to use checksums |
110108e53548e97dbb8ec221a8e418e9be4a79962bf4b9d7023f5e2b495e990b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Release files / loggingx_py-0.5.0-py3-none-any.whl
| Download URL | loggingx_py-0.5.0-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
70501b2222201816a398ab36b71408e6ba72f4525f876e3e3681a9f496a43c63
|
|
BLAKE2b-256 checksum How to use checksums |
49bd3452b0ee727f78e82504bf66612ec193006aad85e2238c45daa3699dab4e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Security for loggingx-py 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.