Split proxy access and errors logs

This commit is contained in:
Igor Chubin 2022-10-26 08:41:20 +02:00
parent 34684cb264
commit 8f433de15a
2 changed files with 11 additions and 7 deletions

View file

@ -37,12 +37,13 @@ MYDIR = os.path.abspath(
sys.path.append("%s/lib/" % MYDIR) sys.path.append("%s/lib/" % MYDIR)
import proxy_log 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 metno import create_standard_json_from_metno, metno_request
from translations import PROXY_LANGS from translations import PROXY_LANGS
# pylint: enable=wrong-import-position # 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(): def is_testmode():
"""Server is running in the wttr.in test mode""" """Server is running in the wttr.in test mode"""
@ -250,10 +251,11 @@ def _fetch_content_and_headers(path, query_string, **kwargs):
try: try:
data = json.loads(response.content) data = json.loads(response.content)
error = data.get("data", {}).get("error", "") error = data.get("data", {}).get("error", "")
try: if error:
error = error[0]["msg"] try:
except (ValueError, IndexError): error = error[0]["msg"]
error = "invalid error format: %s" % error except (ValueError, IndexError):
error = "invalid error format: %s" % error
break break
except ValueError: except ValueError:
attempts -= 1 attempts -= 1

View file

@ -35,7 +35,9 @@ PNG_CACHE = os.path.join(_DATADIR, "cache/png")
LRU_CACHE = os.path.join(_DATADIR, "cache/lru") LRU_CACHE = os.path.join(_DATADIR, "cache/lru")
LOG_FILE = os.path.join(_LOGDIR, 'main.log') 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') MISSING_TRANSLATION_LOG = os.path.join(_LOGDIR, 'missing-translation/%s.log')