Skip to main content
https://img.shields.io/badge/stdlib--only-yes-green.svg https://travis-ci.org/cjrh/logjson.svg?branch=master https://coveralls.io/repos/github/cjrh/logjson/badge.svg?branch=master https://img.shields.io/pypi/pyversions/logjson.svg https://img.shields.io/github/tag/cjrh/logjson.svg https://img.shields.io/badge/install-pip%20install%20logjson-ff69b4.svg https://img.shields.io/pypi/v/logjson.svg https://img.shields.io/badge/calver-YYYY.MM.MINOR-22bfda.svg

logjson

Goal: easily generate structured JSON logging. logstash mode is optional.

import logging
import logjson
logger = logging.getLogger('blah')

handler = logging.StreamHandler()
handler.setFormatter(
    logjson.JSONFormatter(pretty=True)
)
logger.addHandler(handler)

logger.info('hi %s %s!', 'you', 'there')

Output:

{
  "name": "blah",
  "msg": "hi %s %s!",
  "args": [
    "you",
    "there"
  ],
  "levelname": "INFO",
  "levelno": 20,
  "pathname": "<snip>",
  "filename": "test_main.py",
  "module": "test_main",
  "exc_text": null,
  "stack_info": null,
  "lineno": 17,
  "funcName": "test_main",
  "created": 1511750128.6285746,
  "msecs": 628.5746097564697,
  "relativeCreated": 23.08201789855957,
  "thread": 139929130264384,
  "threadName": "MainThread",
  "processName": "MainProcess",
  "process": 18460,
  "message": "hi you there!",
  "created_iso": "2017-11-27T02:35:28.628575+00:00"
}

Logstash mode is only one param away:

logger = logging.getLogger('ls')
handler = logging.StreamHandler()
handler.setFormatter(
    logjson.JSONFormatter(pretty=True, logstash_mode=True)
)
logger.addHandler(handler)
logger.info('logstash test')

Output:

{
  "@message": "logstash test",
  "@source_host": "localhost.localdomain",
  "@timestamp": "2017-11-27T02:35:28.631275+00:00",
  "@fields": {
    "name": "ls",
    "msg": "logstash test",
    "args": [],
    "levelname": "INFO",
    "levelno": 20,
    "pathname": "<snip>",
    "filename": "test_main.py",
    "module": "test_main",
    "exc_text": null,
    "stack_info": null,
    "lineno": 42,
    "funcName": "test_logstash",
    "created": 1511750128.631275,
    "msecs": 631.274938583374,
    "relativeCreated": 25.782346725463867,
    "thread": 139929130264384,
    "threadName": "MainThread",
    "processName": "MainProcess",
    "process": 18460
  }
}

Metadata

Release files for logjson 2020.3.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 logjson 2020.3.1
File Size Uploaded Provenance
logjson-2020.3.1.tar.gz 8.7 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 15.7 kB

Release files / logjson-2020.3.1.tar.gz

Download URL logjson-2020.3.1.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
fc38643fd9cd19954af65904bb9c036540f09fc2cf0be9b85f8ee5ede56ec9d4
BLAKE2b-256 checksum
How to use checksums
ec7592aa98289d5f058d111fd61e87ed417d02939c5f35f507dcbd0178244be3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.23.0

Release files / logjson-2020.3.1-py2.py3-none-any.whl

Download URL logjson-2020.3.1-py2.py3-none-any.whl
Size 7.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
84b3ec165b0d998968e3f498662906daa909fefcd2eaf619199267de5e0fc4b4
BLAKE2b-256 checksum
How to use checksums
202350af92d9e9500a0d16e1ad06758663fd7cdc0071634b9a0ac0c275933cca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.23.0

Security for logjson 2020.3.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.

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