root: ensure manual loggers also have timestamp

This commit is contained in:
Jens Langhammer 2020-11-16 01:41:33 +01:00
parent dda1217735
commit 5faafbbca6
3 changed files with 11 additions and 2 deletions

View File

@ -3,7 +3,7 @@
import passbook. This is done by the dockerfile."""
from json import dumps
from sys import stderr
from time import sleep
from time import sleep, time
from psycopg2 import OperationalError, connect
from redis import Redis
@ -19,6 +19,7 @@ def j_print(event: str, log_level: str = "info", **kwargs):
"event": event,
"level": log_level,
"logger": __name__,
"timestamp": time(),
}
data.update(**kwargs)
print(dumps(data), file=stderr)

View File

@ -4,6 +4,7 @@ from collections.abc import Mapping
from contextlib import contextmanager
from glob import glob
from json import dumps
from time import time
from typing import Any, Dict
from urllib.parse import urlparse
@ -60,7 +61,12 @@ class ConfigLoader:
def _log(self, level: str, message: str, **kwargs):
"""Custom Log method, we want to ensure ConfigLoader always logs JSON even when
'structlog' or 'logging' hasn't been configured yet."""
output = {"event": message, "level": level, "logger": self.__class__.__module__}
output = {
"event": message,
"level": level,
"logger": self.__class__.__module__,
"timestamp": time(),
}
output.update(kwargs)
print(dumps(output))

View File

@ -14,6 +14,7 @@ import importlib
import os
import sys
from json import dumps
from time import time
import structlog
from celery.schedules import crontab
@ -36,6 +37,7 @@ def j_print(event: str, log_level: str = "info", **kwargs):
"event": event,
"level": log_level,
"logger": __name__,
"timestamp": time(),
}
data.update(**kwargs)
print(dumps(data), file=sys.stderr)