Teil 27: logging.config

This commit is contained in:
Olli Graf
2024-10-14 16:09:41 +02:00
parent d4165b0582
commit fd50a8628c
12 changed files with 148 additions and 24 deletions

10
teil27/JSONFormatter.py Normal file
View File

@@ -0,0 +1,10 @@
import logging
import logging.config
import json
ATTR_TO_JSON = ['created', 'filename', 'funcName', 'levelname', 'lineno', 'module', 'msecs', 'msg', 'name', 'pathname', 'process', 'processName', 'relativeCreated', 'thread', 'threadName']
class JsonFormatter:
def format(self, record):
obj = {attr: getattr(record, attr)
for attr in ATTR_TO_JSON}
return json.dumps(obj, indent=4)