improved the logging

Dieser Commit ist enthalten in:
Sebastian Tobie 2024-03-06 21:33:44 +01:00
Ursprung 19a583b6fc
Commit 7c1a1d176d
1 geänderte Dateien mit 9 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -11,7 +11,7 @@ from gunicorn.glogging import CONFIG_DEFAULTS
from gunicorn.glogging import Logger as gLogger
import traceback
__version__ = "0.0.5"
__version__ = "0.0.6"
CONFIG_DEFAULTS = {
@ -79,7 +79,11 @@ class Logger(gLogger):
"""See http://httpd.apache.org/docs/2.0/logs.html#combined
for format details
"""
level = self.access_log.info
if resp.status_code >= 400:
level = self.access_log.warning
elif resp.status_code >= 500
level = self.access_log.error
# wrap atoms:
# - make sure atoms will be test case insensitively
# - if atom doesn't exist replace it by '-'
@ -90,6 +94,8 @@ class Logger(gLogger):
QUERY=environ.get("QUERY_STRING"),
PROTOCOL=environ.get("SERVER_PROTOCOL"),
TIME="%d.%06d" % (request_time.seconds, request_time.microseconds),
STATUS_CODE=resp.status_code,
CODE_ARGS=None,
)
if environ.get("REMOTE_ADDR", False):
extra["REMOTE"] = environ.get("REMOTE_ADDR")
@ -101,6 +107,6 @@ class Logger(gLogger):
extra["USER_AGENT"] = environ.get("HTTP_USER_AGENT")
try:
self.access_log.info(self.cfg.access_log_format, safe_atoms, extra=extra)
level(self.cfg.access_log_format, safe_atoms, extra=extra)
except Exception:
self.error(traceback.format_exc())