Skip to main content

yet-another-json-logger

Yet another JSON logger.

Complete with opinionated decisions and hardcoded personal preferences.

Usage

import logging

from yajl import JsonFormatter

json_handler = logging.FileHandler('log.json')
json_handler.setFormatter(JsonFormatter())

logger = logging.getLogger(__name__)
logger.addHandler(json_handler)
logger.setLevel(logging.INFO)

logger.info('Alice says %r', 'hi!')
try:
    1 / 0
except ZeroDivisionError:
    logger.exception('Bob divided by zero!')

Will result in log.json containing:

{"hostname": "alen-dev-vm", "pwd": "/mnt/alen/dev/yet-another-json-logger", "user": "alen", "name": "__main__", "module": "test", "level": {"name": "INFO", "number": 20}, "file": {"path": "/mnt/alen/dev/yet-another-json-logger/test.py", "filename": "test.py", "line": 12, "func": "<module>"}, "timestamp": {"abs": 1618609778.928479, "rel": 839.9991989135742}, "proc": {"id": 36424, "name": "MainProcess"}, "thread": {"id": 24544, "name": "MainThread"}, "message": "Alice says 'hi!'"}
{"hostname": "alen-dev-vm", "pwd": "/mnt/alen/dev/yet-another-json-logger", "user": "alen", "name": "__main__", "module": "test", "level": {"name": "ERROR", "number": 40}, "file": {"path": "/mnt/alen/dev/yet-another-json-logger/test.py", "filename": "test.py", "line": 16, "func": "<module>"}, "timestamp": {"abs": 1618609778.928479, "rel": 839.9991989135742}, "proc": {"id": 36424, "name": "MainProcess"}, "thread": {"id": 24544, "name": "MainThread"}, "message": "Bob divided by zero!\nTraceback (most recent call last):\n  File \"/mnt/alen/dev/yet-another-json-logger/test.py\", line 14, in <module>\n    1 / 0\nZeroDivisionError: division by zero", "exception": {"type": "builtins.ZeroDivisionError", "str": "division by zero", "traceback": "  File \"/mnt/alen/dev/yet-another-json-logger/test.py\", line 14, in <module>\n    1 / 0\n"}}

or, if prettified:

{
   "hostname": "alen-dev-vm",
   "pwd": "/mnt/alen/dev/yet-another-json-logger",
   "user": "alen",
   "name": "__main__",
   "module": "test",
   "level": {
      "name": "INFO",
      "number": 20
   },
   "file": {
      "path": "/mnt/alen/dev/yet-another-json-logger/test.py",
      "filename": "test.py",
      "line": 12,
      "func": "<module>"
   },
   "timestamp": {
      "abs": 1618609778.928479,
      "rel": 839.9991989135742
   },
   "proc": {
      "id": 36424,
      "name": "MainProcess"
   },
   "thread": {
      "id": 24544,
      "name": "MainThread"
   },
   "message": "Alice says 'hi!'"
}
{
   "hostname": "alen-dev-vm",
   "pwd": "/mnt/alen/dev/yet-another-json-logger",
   "user": "alen",
   "name": "__main__",
   "module": "test",
   "level": {
      "name": "ERROR",
      "number": 40
   },
   "file": {
      "path": "/mnt/alen/dev/yet-another-json-logger/test.py",
      "filename": "test.py",
      "line": 16,
      "func": "<module>"
   },
   "timestamp": {
      "abs": 1618609778.928479,
      "rel": 839.9991989135742
   },
   "proc": {
      "id": 36424,
      "name": "MainProcess"
   },
   "thread": {
      "id": 24544,
      "name": "MainThread"
   },
   "message": "Bob divided by zero!\nTraceback (most recent call last):\n  File \"/mnt/alen/dev/yet-another-json-logger/test.py\", line 14, in <module>\n    1 / 0\nZeroDivisionError: division by zero",
   "exception": {
      "type": "builtins.ZeroDivisionError",
      "str": "division by zero",
      "traceback": "  File \"/mnt/alen/dev/yet-another-json-logger/test.py\", line 14, in <module>\n    1 / 0\n"
   }
}

Release files for yet-another-json-logger 0.1.0

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

Source distribution (sdist)

Source distribution for yet-another-json-logger 0.1.0
File Size Uploaded
yet-another-json-logger-0.1.0.tar.gz 10.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for yet-another-json-logger 0.1.0
File Interpreter ABI Platform
yet_another_json_logger-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.6 kB

Release files / yet-another-json-logger-0.1.0.tar.gz

Download URL yet-another-json-logger-0.1.0.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d75a0b3354317d576c5795d7e1f41688370115d29b07ae4fae68b30e58fa2044
BLAKE2b-256 checksum
How to use checksums
bc3f770c0acd4dad187fad981ecebcc279546d96472c49bcd91baf1ff7dc1790
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.10.0a6

Release files / yet_another_json_logger-0.1.0-py3-none-any.whl

Download URL yet_another_json_logger-0.1.0-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
21a85db605805eba403a225bea7df2beb09e6bda6ce9c0703c65d6da0353d86a
BLAKE2b-256 checksum
How to use checksums
5c6b2432a7178c40701434cbf95d2e2ca1f40f3338ff2fd77eb61dae14fa8b21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.10.0a6

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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