Skip to main content

Configs for python's logging library to have a JSONL-log

Project description

TestStatus PyPiStatus BlackStyle BlackPackStyle MITLicenseBadge

Uses python’s awesome logging-library and configures it to write JSON-lines. In JSON-lines, each line in the log is a valid json-object. This makes the log easy to read with a machine.

install

pip install json-line-logger

usage

There are three handy constructors for loggers: LoggerFile, LoggerStream, and LoggerStdout.

import json_line_logger

logger = json_line_logger.LoggerFile(path="test.log.jsonl")

logger.debug("This is a log message")

with json_line_logger.TimeDelta(logger=logger, name="some costly task"):
    result_of_a_costly_task = 1 + 1

json_line_logger.shutdown(logger=logger)

Yields a logfile test.log.jsonl which contains:

{"t":"1886-03-27T11:01:01.341", "l":"DEBUG", "m":"This is a log message"}
{"t":"1886-03-27T11:01:01.341", "l":"INFO", "m":"<TimeDelta name='some costly task' delta='2.1457672119140625e-06'/>"}

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

json_line_logger-0.0.10.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

json_line_logger-0.0.10-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file json_line_logger-0.0.10.tar.gz.

File metadata

  • Download URL: json_line_logger-0.0.10.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for json_line_logger-0.0.10.tar.gz
Algorithm Hash digest
SHA256 7f6c2fe0e3bcbeb01225b99e92ab3dbd2d8e75d9449649d0b5d0f474bcd3e9d0
MD5 f17df739663211dcbc7e396d029bdb87
BLAKE2b-256 c682001c887403a6034150037dac7a40c258a0380dcceae7a8da97346dcb3127

See more details on using hashes here.

File details

Details for the file json_line_logger-0.0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for json_line_logger-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 c3f5ece77cc076d08dd716c3a1af55a6f7f07930bacd880497ec4e65a6174c56
MD5 4974884508f0d1c72d7530b10d4e352c
BLAKE2b-256 ea60216716366c0cd487037370d621f42be4b2822e435ff241eaf9fbb173b128

See more details on using hashes here.

Supported by

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