Drop-in replacement for Python's built-in `logging` module
Project description
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"})
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
loggingx-py-0.4.0.tar.gz
(39.6 kB
view details)
Built Distribution
File details
Details for the file loggingx-py-0.4.0.tar.gz
.
File metadata
- Download URL: loggingx-py-0.4.0.tar.gz
- Upload date:
- Size: 39.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
481438ac1e510581b2ee5b0d784b2647c4e703ddb5e33f33ae6a0280f4b0a84d
|
|
MD5 |
16fef7d49cbd1292c7cb0aece769efdc
|
|
BLAKE2b-256 |
5c417a3bc70942b2ee783d06b1d18cf0dc985478396007401859d836f8876bc3
|
File details
Details for the file loggingx_py-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: loggingx_py-0.4.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
420db95b8fbb51f879c3759632fd161cd132d024d1eff3bb9acdcf98c4cbda85
|
|
MD5 |
fb58efc4897eb7c0777a6c619a6ccb15
|
|
BLAKE2b-256 |
2c88449c2ac90b85630c2f2f3933368d88da564fcee25a55b76a4655de40fda4
|