replaced the atoms replacement with the accesslogreplacement

Dieser Commit ist enthalten in:
Sebastian Tobie 2024-03-05 11:03:35 +01:00
Ursprung e8930ca288
Commit 21dc03b139
1 geänderte Dateien mit 30 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -10,7 +10,7 @@ from logging.config import dictConfig, fileConfig
from gunicorn.glogging import CONFIG_DEFAULTS from gunicorn.glogging import CONFIG_DEFAULTS
from gunicorn.glogging import Logger as gLogger from gunicorn.glogging import Logger as gLogger
__version__ = "0.0.2" __version__ = "0.0.3"
class Logger(gLogger): class Logger(gLogger):
@ -50,16 +50,30 @@ class Logger(gLogger):
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( fileConfig(cfg.logconfig, defaults=defaults, disable_existing_loggers=False)
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)
def atoms(self, resp, req, environ, request_time): def access(self, resp, req, environ, request_time):
atoms = super().atoms(resp, req, environ, request_time) """See http://httpd.apache.org/docs/2.0/logs.html#combined
atoms["extra"] = dict( for format details
"""
if not (
self.cfg.accesslog
or self.cfg.logconfig
or self.cfg.logconfig_dict
or self.cfg.logconfig_json
or (self.cfg.syslog and not self.cfg.disable_redirect_access_to_syslog)
):
return
# wrap atoms:
# - make sure atoms will be test case insensitively
# - if atom doesn't exist replace it by '-'
safe_atoms = self.atoms_wrapper_class(self.atoms(resp, req, environ, request_time))
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"),
@ -67,11 +81,15 @@ class Logger(gLogger):
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") extra["remote"] = environ.get("REMOTE_ADDR")
if getattr(resp, "sent", False): if getattr(resp, "sent", False):
atoms["extra"]["length"] = getattr(resp, "sent") extra["length"] = getattr(resp, "sent")
if environ.get("HTTP_REFERER", False): if environ.get("HTTP_REFERER", False):
atoms["extra"]["referer"] = environ.get("HTTP_REFERER") 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") extra["user_agent"] = environ.get("HTTP_USER_AGENT")
return atoms
try:
self.access_log.info(self.cfg.access_log_format, safe_atoms, extra=extra)
except Exception:
self.error(traceback.format_exc())