A simple JSON logger, used for structured logging
Project description
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"
}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yet-another-json-logger-0.1.0.tar.gz.
File metadata
- Download URL: yet-another-json-logger-0.1.0.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d75a0b3354317d576c5795d7e1f41688370115d29b07ae4fae68b30e58fa2044
|
|
| MD5 |
3ffc109e8c6a752dbfdabc5f1c1a5330
|
|
| BLAKE2b-256 |
bc3f770c0acd4dad187fad981ecebcc279546d96472c49bcd91baf1ff7dc1790
|
File details
Details for the file yet_another_json_logger-0.1.0-py3-none-any.whl.
File metadata
- Download URL: yet_another_json_logger-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21a85db605805eba403a225bea7df2beb09e6bda6ce9c0703c65d6da0353d86a
|
|
| MD5 |
5425d2d9ff045139061151881fa12fa5
|
|
| BLAKE2b-256 |
5c6b2432a7178c40701434cbf95d2e2ca1f40f3338ff2fd77eb61dae14fa8b21
|