From ea20fb93d3110800fe1f2e7c6351486fcf9a8514 Mon Sep 17 00:00:00 2001 From: Bernhard Mallinger <bernhard.mallinger@eox.at> Date: Mon, 21 Feb 2022 14:18:32 +0100 Subject: [PATCH] Setup config for structured logging --- registrar/cli.py | 14 +++++++++++--- requirements.txt | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/registrar/cli.py b/registrar/cli.py index edfd96e..208136e 100644 --- a/registrar/cli.py +++ b/registrar/cli.py @@ -2,6 +2,7 @@ from os.path import join, dirname import logging.config import click +import structlog import yaml import jsonschema @@ -22,13 +23,20 @@ def setup_logging(debug=False): { "version": 1, "disable_existing_loggers": False, - "formatters": {"brief": {"format": "%(levelname)s %(name)s: %(message)s"}}, + "formatters": { + "json": { + "()": structlog.stdlib.ProcessorFormatter, + "processor": structlog.processors.JSONRenderer(), + # For nicer cli output: + # "processor": structlog.dev.ConsoleRenderer(), + }, + }, "handlers": { "console": { "class": "logging.StreamHandler", "level": "DEBUG" if debug else "INFO", - "formatter": "brief", - } + "formatter": "json", + }, }, "root": { "handlers": ["console"], diff --git a/requirements.txt b/requirements.txt index 6435967..f86eb65 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,5 +6,6 @@ pyyaml<6.0 jsonschema<5.0 boto3<2.0 django-cors-headers<4.0 +django-structlog==2.2. pystac<2.0 http-access==0.1.3 -- GitLab