Added json logger
All checks were successful
Build & Publish to GHCR / build (push) Successful in 44s
All checks were successful
Build & Publish to GHCR / build (push) Successful in 44s
This commit is contained in:
parent
5d1b680ae3
commit
6cb52c1b2a
@ -17,5 +17,6 @@ propcache==0.4.1
|
||||
pycares==4.11.0
|
||||
pycparser==2.23
|
||||
PyMySQL==1.1.2
|
||||
python-json-logger==4.0.0
|
||||
typing_extensions==4.15.0
|
||||
yarl==1.22.0
|
||||
|
||||
@ -1,5 +1,11 @@
|
||||
import logging
|
||||
import os
|
||||
import logging
|
||||
|
||||
try:
|
||||
from pythonjsonlogger import jsonlogger
|
||||
JSON_LOGGING = True
|
||||
except ImportError:
|
||||
JSON_LOGGING = False
|
||||
|
||||
LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO").upper()
|
||||
if LOG_LEVEL not in {"ERROR", "DEBUG", "INFO", "WARNING", "CRITICAL"}:
|
||||
@ -9,8 +15,13 @@ def setup_logger(name: str) -> logging.Logger:
|
||||
logger = logging.getLogger(name)
|
||||
if not logger.handlers:
|
||||
handler = logging.StreamHandler()
|
||||
if JSON_LOGGING:
|
||||
formatter = jsonlogger.JsonFormatter(
|
||||
"%(asctime)s %(name)s %(levelname)s %(message)s"
|
||||
)
|
||||
else:
|
||||
formatter = logging.Formatter(
|
||||
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
||||
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
||||
)
|
||||
handler.setFormatter(formatter)
|
||||
logger.addHandler(handler)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user