fixed the imports

Dieser Commit ist enthalten in:
Sebastian Tobie 2024-03-05 00:39:39 +01:00
Ursprung 202ac12f7a
Commit 13b18c2b62
1 geänderte Dateien mit 32 neuen und 21 gelöschten Zeilen

Datei anzeigen

@ -1,13 +1,16 @@
# SPDX-FileCopyrightText: 2024-present Sebastian Tobie <sebastian@sebastian-tobie.de> # SPDX-FileCopyrightText: 2024-present Sebastian Tobie <sebastian@sebastian-tobie.de>
# #
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
from gunicorn.glogging import Logger as gLogger import json
from logging import Formatter import logging
from logging.config import dictConfig
from logging.config import fileConfig
import os.path import os.path
import threading
from logging.config import dictConfig, fileConfig
__version__ = "0.0.1" from gunicorn.glogging import CONFIG_DEFAULTS
from gunicorn.glogging import Logger as gLogger
__version__ = "0.0.2"
class Logger(gLogger): class Logger(gLogger):
@ -34,14 +37,22 @@ class Logger(gLogger):
config_json = json.load(open(cfg.logconfig_json)) config_json = json.load(open(cfg.logconfig_json))
config.update(config_json) config.update(config_json)
dictConfig(config) dictConfig(config)
except (json.JSONDecodeError, AttributeError, ImportError, ValueError, TypeError) as exc: except (
json.JSONDecodeError,
AttributeError,
ImportError,
ValueError,
TypeError,
) as exc:
raise RuntimeError(str(exc)) raise RuntimeError(str(exc))
elif cfg.logconfig: elif cfg.logconfig:
if os.path.exists(cfg.logconfig): if os.path.exists(cfg.logconfig):
defaults = CONFIG_DEFAULTS.copy() defaults = CONFIG_DEFAULTS.copy()
defaults['__file__'] = cfg.logconfig defaults["__file__"] = cfg.logconfig
defaults['here'] = os.path.dirname(cfg.logconfig) defaults["here"] = os.path.dirname(cfg.logconfig)
fileConfig(cfg.logconfig, defaults=defaults, disable_existing_loggers=False) fileConfig(
cfg.logconfig, defaults=defaults, disable_existing_loggers=False
)
else: else:
msg = "Error: log config '%s' not found" msg = "Error: log config '%s' not found"
raise RuntimeError(msg % cfg.logconfig) raise RuntimeError(msg % cfg.logconfig)
@ -49,18 +60,18 @@ class Logger(gLogger):
def atoms(self, resp, req, environ, request_time): def atoms(self, resp, req, environ, request_time):
atoms = super().atoms(resp, req, environ, request_time) atoms = super().atoms(resp, req, environ, request_time)
atoms["extra"] = dict( atoms["extra"] = dict(
method=environ.get('REQUEST_METHOD'), method=environ.get("REQUEST_METHOD"),
path=environ.get('PATH_INFO'), path=environ.get("PATH_INFO"),
query=environ.get('QUERY_STRING'), query=environ.get("QUERY_STRING"),
proto=environ.get('SERVER_PROTOCOL'), proto=environ.get("SERVER_PROTOCOL"),
time="%d.%06d" % (request_time.seconds, request_time.microseconds), time="%d.%06d" % (request_time.seconds, request_time.microseconds),
) )
if environ.get('REMOTE_ADDR', False): if environ.get("REMOTE_ADDR", False):
atoms["extra"]["remote"] = environ.get('REMOTE_ADDR') atoms["extra"]["remote"] = environ.get("REMOTE_ADDR")
if getattr(resp, 'sent', False): if getattr(resp, "sent", False):
atoms["extra"]["length"] = getattr(resp, 'sent') atoms["extra"]["length"] = getattr(resp, "sent")
if environ.get('HTTP_REFERER', False): if environ.get("HTTP_REFERER", False):
atoms["extra"]["referer"] = environ.get('HTTP_REFERER') atoms["extra"]["referer"] = environ.get("HTTP_REFERER")
if environ.get('HTTP_USER_AGENT', False): if environ.get("HTTP_USER_AGENT", False):
atoms["extra"]["user_agent"] = environ.get('HTTP_USER_AGENT') atoms["extra"]["user_agent"] = environ.get("HTTP_USER_AGENT")
return atoms return atoms