Skip to main content
https://travis-ci.org/podhmo/nejimaki.svg?branch=master

contextual logging library, no patch, no logging module replacement

features

  • structured logging

  • contextual logging (via logger.bind)

  • (no conflicts (stdlib’s logging module))

example

main.py

from monokaki import basic_config, get_logger
import logging

logger = get_logger(__name__)


def run(log):
    log.info("hello")
    log.debug("hmm..")


def main():
    log = logger.bind(name="foo")
    run(log)
    logger.info("bye")

    # normal stdlib's logger
    normallogger = logging.getLogger("stdlib's")
    normallogger.info("hai")


if __name__ == "__main__":
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--logging", choices=list(sorted(logging._nameToLevel.keys())), default="INFO"
    )
    args = parser.parse_args()
    basic_config(level=logging._nameToLevel[args.logging])
    main()
$ python examples/readme/main.py
{"level": "INFO", "logger": "__main__", "msg": "hello", "name": "foo", "time": "2017-05-21 16:03:44,306"}
{"level": "INFO", "logger": "__main__", "msg": "bye", "time": "2017-05-21 16:03:44,307"}
INFO:stdlib's:hai

$ python examples/readme/main.py --logging=DEBUG
{"level": "INFO", "logger": "__main__", "msg": "hello", "name": "foo", "time": "2017-05-21 16:03:44,427"}
{"level": "DEBUG", "logger": "__main__", "msg": "hmm..", "name": "foo", "time": "2017-05-21 16:03:44,427"}
{"level": "INFO", "logger": "__main__", "msg": "bye", "time": "2017-05-21 16:03:44,428"}
INFO:stdlib's:hai

output customization

renderer.py

import json
from collections import OrderedDict


def ordered_json_render(data, record, formatter):
    kwargs = OrderedDict()
    # see: https://docs.python.org/3/library/logging.html#formatter-objects
    kwargs["time"] = formatter.formatTime(record)

    # see: https://docs.python.org/3/library/logging.html#logrecord-attributes
    kwargs["level"] = record.levelname
    kwargs["meg"] = record.msg
    kwargs["caller"] = "{}:{}".format(record.pathname, record.lineno)
    kwargs["source"] = record.name

    # support exc_info or stack_info
    if "stack" in data:
        kwargs["stack"] = data["stack"]

    # extra data
    kwargs.update(record.kwargs)
    return json.dumps(kwargs, indent=2)

main.py

from monokaki import get_logger, basic_config
logger = get_logger(__name__)


def main():
    logger.bind(name="foo").info("hello", age=20)
    logger.bind(name="foo").info("bye", age=21)


if __name__ == "__main__":
    import logging
    from renderer import ordered_json_render
    basic_config(level=logging.INFO, renderer=ordered_json_render)
    main()
$ python examples/customize-renderer/main.py
{
  "time": "2017-05-21 16:03:44,645",
  "level": "INFO",
  "meg": "hello",
  "caller": "examples/customize-renderer/main.py:6",
  "source": "__main__",
  "name": "foo",
  "age": 20
}
{
  "time": "2017-05-21 16:03:44,646",
  "level": "INFO",
  "meg": "bye",
  "caller": "examples/customize-renderer/main.py:7",
  "source": "__main__",
  "name": "foo",
  "age": 21
}

Metadata

Release files for monokaki 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for monokaki 0.1.1
File Size Uploaded Provenance Actions
monokaki-0.1.1.tar.gz 3.6 kB Without provenance Details for monokaki-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for monokaki 0.1.1
File Interpreter ABI Platform Actions
monokaki-0.1.1-py2.py3-none-any.whl Python 3, Python 2 none any Details for monokaki-0.1.1-py2.py3-none-any.whl

Total release size: 9.3 kB

Release files / monokaki-0.1.1.tar.gz

Download URL monokaki-0.1.1.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4bb4ac182dbe8cb20b7ce1270e47d3393e6885e2d57b5a0f72e8314526638eb6
BLAKE2b-256 checksum
How to use checksums
fd7652a8416b20863f3c2423fd338f5bcbe0d637b39220616d1356dca854acb9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / monokaki-0.1.1-py2.py3-none-any.whl

Download URL monokaki-0.1.1-py2.py3-none-any.whl
Size 5.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
a816e60581e167af8c5e6c0bccf60e76a56c003f0ae224bc97202df7592731dc
BLAKE2b-256 checksum
How to use checksums
eb6fb54f3f5677ddbf751a464e49589a0a56900e0b33518109564f4e352e82b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for monokaki 0.1.1

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page