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
Clone the git repo
git clone git@github.com:MattLimb/pylogformats.git
Install
python3 -m pip install pylogformats
Usage
Use the formatter as you would any other Python Formatter:
import pylogformat
import logging
import sys
logger = logging.getLogger()
logHandler = logging.StreamHandler(sys.stdout)
formatter = pylogformat.AdvJSONFormat()
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
pyLogFormats-0.1.1.tar.gz
(3.9 kB
view hashes)
Built Distribution
Close
Hashes for pyLogFormats-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8427850bf0e339218ad5a3be21a97c2f3e51db42e0536e7b6af028853db4850 |
|
MD5 | a7e7205814c5ad3310ae80db12d466b8 |
|
BLAKE2b-256 | ca2127435e94d95c82db531a2025b1315422690b9b12fa7e9b005257fed924c5 |