A collection of useful log formats for Python Loggers.
Project description
pyLogFormats
A collection of Logging Formats for the Pyton Standard Logger. Thats it.
Right now, this is a fairly small list, however there are a few log formats that I'd like to add. Checkout the Future Additions Section below.
Github-flavored Markdown to write your content.
Formats Included:
- BunyanFormat (https://github.com/trentm/node-bunyan)
{
"time": "2021-02-04T23:01:00.781Z",
"name": "root",
"pid": 15504,
"level": 40,
"msg": "TEST",
"hostname": "Sophie",
"v": 0
}
- JSONFormat
{
"logger": "root",
"timestamp": "2021-02-04T23:01:46.435011",
"message": "TEST",
"level": "ERROR",
"levelno": 40,
"function": "<module>",
"process": {
"number": 13316,
"name": "MainProcess"
},
"thread": {
"number": 10704,
"name": "MainThread"
},
"v": 1
}
- AdvJSONFormat (For Verbose JSON Logging)
{
"logger": "root",
"timestamp": "2021-02-04T23:02:52.522958",
"rtimestamp": "2021-02-04T23:02:37.518800",
"message": "TEST",
"level": "ERROR",
"levelno": 40,
"location": {
"pathname": "<FULL_PATH>\\test_logger.py",
"module": "test_logger",
"filename": "test_logger.py",
"function": "<module>",
"line": 16
},
"process": {
"number": 2300,
"name": "MainProcess"
},
"thread": {
"number": 12516,
"name": "MainThread"
},
"v": 1
}
Installation
Install via pip
python3 -m pip install pylogformats
Usage
Use the formatter as you would any other Python Formatter:
import pylogformats
import logging
import sys
logger = logging.getLogger()
logHandler = logging.StreamHandler(sys.stdout)
formatter = pylogformats.JSONFormat()
logHandler.setFormatter(formatter)
logger.addHandler(logHandler)
logger.setLevel(logging.DEBUG)
You can also use dictConfig:
LOG_CONFIG = {
'formatters': {
'jsonformatter': {
'()' : 'pylogformats.JSONFormat'
}
},
'handlers': {
'debug': {
'class': 'logging.StreamHandler',
'formatter': 'jsonformatter',
'stream': 'ext://sys.stdout'
},
},
'root': {
'level': 'DEBUG',
'handlers': ['debug']
},
'version': 1
}
import logging.config
logging.config.dictConfig(LOG_CONFIG)
Project details
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 pyLogFormats-0.2.2.tar.gz.
File metadata
- Download URL: pyLogFormats-0.2.2.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90bed29c774cf74bf9bfd749072687b0b506de193ab55a8c963e454496b6f6ea
|
|
| MD5 |
20016d3df23b1349e09629219e81b7ab
|
|
| BLAKE2b-256 |
9b4460356934e2bdcca155e791d1a85256b7423d27f072938c2b2cc1f583755a
|
File details
Details for the file pylogformats-0.2.2-py3-none-any.whl.
File metadata
- Download URL: pylogformats-0.2.2-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6897a87d404249a17dc47534d0e5a6c47c0a3795e78304cc0bbd0b471ec73c1
|
|
| MD5 |
4f70368092d77e4d51cfeb981241ac5d
|
|
| BLAKE2b-256 |
a37f1d12e1bfdbb77b2cb2bf59dc001df5bc5044b8db98c4f41d805aa36ac1c3
|