JSON Logging
Write your logs as json-lines.
Source Code |
|
Downloads |
json-scribe @ pypi.org |
This library is the result of sending docker container logs to loggly. Loggly works well with structured Syslog data but if you pass structured Syslog lines to an aggregator as JSON you end up with an unindexed mess. This library includes a few classes that make it easier and cleaner to send log content as JSON objects on single lines including exceptions.
Usage
Configuration
{
"version": 1,
"filters": {
"defaultsetter": {
"()": "jsonscribe.AttributeSetter",
"add_fields": {
"correlation_id": "ext://UUID"
}
}
},
"formatters": {
"jsonlines": {
"()": "jsonscribe.JSONFormatter",
"include_fields": [
"name",
"levelname",
"asctime",
"message",
"module",
"correlation_id",
"exc_info"
],
}
},
"handlers": {
"loggly": {
"class": "logging.StreamHandler",
"formatter": "jsonlines",
"filters": ["defaultsetter"],
"stream": "ext://sys.stdout"
}
},
"loggers": {
"somepackage": {
"level": "DEBUG",
}
},
"root": {
"level": "INFO",
"handlers": ["jsonlines"]
}
}
Logging
The following snippet is the simplest usage. It is nothing more than the textbook usage of the logging module. It uses the logging configuration from above and generates a JSON blob.
import logging.config
import json
if __name__ == '__main__':
config = json.load(open('config.json'))
logging.config.dictConfig(config)
logger = logging.getLogger(__package__).getChild('main')
logger.info('processing request')
The JSON message looks something like the following. It is reformatted to make it readable. The default is to render it as compact JSON.
{
"name": "somepackage.main",
"levelname": "INFO",
"asctime": "2018-08-09T07:44:54.231",
"module": "somepackage.entrypoints",
"correlation_id": "33CA3FB3-D66F-4D32-83A5-D5A8C3D92A6E",
"message": "processing request",
"exc_info": null
}
Metadata
Release files for json-scribe 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| json-scribe-2.0.0.tar.gz | 9.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| json_scribe-2.0.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 15.6 kB
Release files / json-scribe-2.0.0.tar.gz
| Download URL | json-scribe-2.0.0.tar.gz |
|---|---|
| Size | 9.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d3cfb1267dd4de61f7c3fe9a846427cac0bfc368d19d9ffb569ee46aef2b8d15
|
|
BLAKE2b-256 checksum How to use checksums |
dc8cdb949f599592942cb624a18c9773f3daeb79fd1e45a7e49bec41f0039632
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5
|
Release files / json_scribe-2.0.0-py2.py3-none-any.whl
| Download URL | json_scribe-2.0.0-py2.py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
d846bb7033ab4aab95a034935e6e460e10a4bf300a4ab67f64798954b3616351
|
|
BLAKE2b-256 checksum How to use checksums |
92a848c28ab9f2ae510c7b7881e3947dfa1db82cd7f0b730d7cf2c91ea462555
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5
|
Security for json-scribe 2.0.0
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.