From 8f433de15a4fbdb507c9031310b2b24e0f297a72 Mon Sep 17 00:00:00 2001 From: Igor Chubin Date: Wed, 26 Oct 2022 08:41:20 +0200 Subject: [PATCH] Split proxy access and errors logs --- bin/proxy.py | 14 ++++++++------ lib/globals.py | 4 +++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/bin/proxy.py b/bin/proxy.py index 499fde7..02af224 100755 --- a/bin/proxy.py +++ b/bin/proxy.py @@ -37,12 +37,13 @@ MYDIR = os.path.abspath( sys.path.append("%s/lib/" % MYDIR) import proxy_log -from globals import PROXY_CACHEDIR, PROXY_HOST, PROXY_PORT, USE_METNO, USER_AGENT, MISSING_TRANSLATION_LOG, PROXY_LOG_FILE +import globals +from globals import PROXY_CACHEDIR, PROXY_HOST, PROXY_PORT, USE_METNO, USER_AGENT, MISSING_TRANSLATION_LOG from metno import create_standard_json_from_metno, metno_request from translations import PROXY_LANGS # pylint: enable=wrong-import-position -proxy_logger = proxy_log.LoggerWWO(PROXY_LOG_FILE) +proxy_logger = proxy_log.LoggerWWO(globals.PROXY_LOG_ACCESS, globals.PROXY_LOG_ERRORS) def is_testmode(): """Server is running in the wttr.in test mode""" @@ -250,10 +251,11 @@ def _fetch_content_and_headers(path, query_string, **kwargs): try: data = json.loads(response.content) error = data.get("data", {}).get("error", "") - try: - error = error[0]["msg"] - except (ValueError, IndexError): - error = "invalid error format: %s" % error + if error: + try: + error = error[0]["msg"] + except (ValueError, IndexError): + error = "invalid error format: %s" % error break except ValueError: attempts -= 1 diff --git a/lib/globals.py b/lib/globals.py index 9ad39ca..ccf177d 100644 --- a/lib/globals.py +++ b/lib/globals.py @@ -35,7 +35,9 @@ PNG_CACHE = os.path.join(_DATADIR, "cache/png") LRU_CACHE = os.path.join(_DATADIR, "cache/lru") LOG_FILE = os.path.join(_LOGDIR, 'main.log') -PROXY_LOG_FILE = os.path.join(_LOGDIR, 'proxy.log') + +PROXY_LOG_ACCESS = os.path.join(_LOGDIR, 'proxy-access.log') +PROXY_LOG_ERRORS = os.path.join(_LOGDIR, 'proxy-errors.log') MISSING_TRANSLATION_LOG = os.path.join(_LOGDIR, 'missing-translation/%s.log')