json-pyformatter
Python logging outputs as JSON.
This JsonFormatter is written in Pure Python.
Installation
pip install json-pyformatter
Usage
import logging
from json_pyformmatter import JsonFormatter
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
handler = logging.StreamHandler()
fields = ('levelname', 'filename', 'message')
handler.setFormatter(JsonFormatter(fields=fields))
logger.addHandler(hander)
logger.info('hello')
default fields is ('asctime', 'levelname', 'message')
Other supported fields are:
| field name | description |
|---|---|
| name | Name of the logger (logging channel) |
| levelno | Numeric logging level for the message (DEBUG, INFO, WARNING, ERROR, CRITICAL) |
| levelname | Text logging level for the message ("DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL") |
| pathname | Full pathname of the source file where the logging call was issued |
| filename | Filename portion of pathname |
| module | Module (name portion of filename) |
| lineno | Source line number where the logging call was issued |
| funcName | Function name |
| created | Time when the LogRecord was created (time.time()return value) |
| asctime | Textual time when the LogRecord was created |
| msecs | Millisecond portion of the creation time |
| relativeCreated | Time in milliseconds when the LogRecord was created, relative to the time the logging module was loaded (typically at application startup time) |
| thread | Thread ID |
| threadName | Thread name |
| process | Process ID |
| message | The result of record.getMessage(), computed just as the record is emitted |
In details, please refere to logrecord-attributes
Output
{"levelname": "INFO", "filename": "test_formatter.py", "message": "hello"}
If specify indent option as 2, the result is as follows:
{
"levelname": "INFO",
"filename": "test_formatter.py",
"message": "hello"
}
When exc_info is True, the result includes traceback infomation as follows:
{
'asctime': '2019-12-01 13:58:34',
'levelname': 'ERROR',
'message': 'error occurred !!',
'traceback': [
'Traceback (most rec...ll last):',
'File "/example/test..._exc_info',
'raise TypeError(message)',
'TypeError: error occurred !!'
]
}
Logging message type is dict:
{
'asctime': '2019-12-01 23:34:32',
'levelname': 'INFO',
'message': {
'id': '001',
'msg': 'This is test.',
'name': 'test'
}
}
Metadata
Release files for json-pyformatter 0.1.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 | Actions |
|---|---|---|---|---|
| json-pyformatter-0.1.0.tar.gz | 4.6 kB | Without provenance | Details for json-pyformatter-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| json_pyformatter-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for json_pyformatter-0.1.0-py3-none-any.whl |
Total release size: 9.4 kB
Release files / json-pyformatter-0.1.0.tar.gz
| Download URL | json-pyformatter-0.1.0.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
006573f9ec788a7e90ed1b1e66b9dd19d55719d76fe7abb28b46ab6889e266f2
|
|
BLAKE2b-256 checksum How to use checksums |
df5964fe142209dde4b4dffaee37d9b0435d8bdaa4833a627f3be1150acc717a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.17 CPython/3.8.0 Linux/5.0.0-1023-azure
|
Release files / json_pyformatter-0.1.0-py3-none-any.whl
| Download URL | json_pyformatter-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bebaeb4780815f7897bc9153ee8bee73788d01981530572c2c3418e296622e95
|
|
BLAKE2b-256 checksum How to use checksums |
a5234a8c36dd23160d6d9aba1f6b2d52a8d6d149215ff4dde764304de2a26177
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.17 CPython/3.8.0 Linux/5.0.0-1023-azure
|
Security for json-pyformatter 0.1.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.