Skip to main content

Drop-in replacement for Python's built-in `logging` module

Project description

license pypi language

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


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.


import loggingx as logging


def A() -> None:"A")
    with logging.addFields(A="a"):

def B() -> None:"B")
    with logging.addFields(B="b"):

def C() -> None:"C")

if __name__ == "__main__":
2023-07-19 01:15:33,981 INFO  A       {}
2023-07-19 01:15:33,981 INFO  B       {'A': 'a'}
2023-07-19 01:15:33,982 INFO  C       {'A': 'a', 'B': 'b'}


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"):"test", extra={"extra": "extra"})
  "time": 1689697694.9980711,
  "level": "info",
  "caller": "",
  "msg": "test",
  "ctx": "ctx",
  "thread_name": "MainThread",
  "extra": "extra"

With logging

import logging

import loggingx

# handler = loggingx.StreamHandler()
handler = logging.StreamHandler()

# loggingx.basicConfig(level=loggingx.INFO, handlers=[handler])
logging.basicConfig(level=logging.INFO, handlers=[handler])

if __name__ == "__main__":
    with loggingx.addFields(ctx="ctx"):
        #"test", extra={"extra": "extra"})"test", extra={"extra": "extra"})


alias log2jq="jq -R -r '. as \$line | try fromjson catch \$line'"
python3 <path> 2>&1 | log2jq

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

loggingx-py-0.8.0.tar.gz (40.5 kB view hashes)

Uploaded Source

Built Distribution

loggingx_py-0.8.0-py3-none-any.whl (6.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page