Skip to content
Snippets Groups Projects
Verified Commit a7ff6e1f authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

Allow logging as json

This will help for the part of the infrastructure not using systemd/journald
log to push introspectable logs.

Ref. swh/infra/sysadm-environment#4524
parent fccf9442
No related branches found
No related tags found
No related merge requests found
Pipeline #173 passed
......@@ -43,3 +43,6 @@ ignore_missing_imports = True
[mypy-simpy.*]
ignore_missing_imports = True
[mypy-pythonjsonlogger.*]
ignore_missing_imports = True
python-json-logger
......@@ -53,6 +53,7 @@ setup(
"testing": parse_requirements("test", "journal", "simulator"),
"journal": parse_requirements("journal"),
"simulator": parse_requirements("simulator"),
"logger-json": parse_requirements("logger-json"),
},
include_package_data=True,
entry_points="""
......
......@@ -94,6 +94,8 @@ def setup_log_handler(
log_console = True
elif log_target == "journal":
log_journal = True
elif log_target == "json":
log_json = True
# this looks for log levels *higher* than DEBUG
if loglevel <= logging.DEBUG and log_console is None:
......@@ -118,6 +120,14 @@ def setup_log_handler(
systemd_journal.setFormatter(formatter)
root_logger.addHandler(systemd_journal)
if log_json:
from pythonjsonlogger import jsonlogger
json_handler = logging.StreamHandler()
formatter = jsonlogger.JsonFormatter()
json_handler.setFormatter(formatter)
root_logger.addHandler(json_handler)
logging.getLogger("celery").setLevel(logging.INFO)
# Silence amqp heartbeat_tick messages
......
......@@ -38,6 +38,7 @@ commands =
[testenv:mypy]
extras =
testing
logger-json
deps =
mypy==0.942
commands =
......@@ -51,6 +52,7 @@ whitelist_externals = make
usedevelop = true
extras =
testing
logger-json
deps =
# fetch and install swh-docs in develop mode
-e git+https://forge.softwareheritage.org/source/swh-docs#egg=swh.docs
......@@ -70,6 +72,7 @@ whitelist_externals = make
usedevelop = true
extras =
testing
logger-json
deps =
# install swh-docs in develop mode
-e ../swh-docs
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment