From 23be164717357b0dee387e8eea96385161630489 Mon Sep 17 00:00:00 2001 From: Olaf Mandel Date: Sat, 5 Oct 2024 22:00:25 +0200 Subject: [PATCH] configuration: add logging_levels section Allow to configure the logging-levels of various loggers by adding a new section `logging_levels` to the configuration file. Each entry in that section configures the logging-level of one logger / channel. --- README.md | 3 +++ p3.yml | 2 ++ p3exporter/__init__.py | 9 ++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 03a6ea4..134939e 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,9 @@ collector_opts: blacklist: - docker0 - lo +logging_levels: + root: INFO + foomodule.barcollector: WARNING ``` ### Start-up Configuration diff --git a/p3.yml b/p3.yml index 3a19363..e737458 100644 --- a/p3.yml +++ b/p3.yml @@ -9,3 +9,5 @@ collector_opts: blacklist: - docker0 - lo +logging_levels: + root: INFO diff --git a/p3exporter/__init__.py b/p3exporter/__init__.py index f2f5df7..46e8f45 100644 --- a/p3exporter/__init__.py +++ b/p3exporter/__init__.py @@ -3,7 +3,7 @@ from wsgiref.simple_server import make_server import yaml -import logging +import logging.config import os import signal import sys @@ -41,6 +41,13 @@ def main(): with open(args.config, 'r') as config_file: cfg = yaml.load(config_file, Loader=yaml.SafeLoader) collector_config = CollectorConfig(**cfg) + if type(cfg.get('logging_levels')) == dict: + levels = cfg['logging_levels'] + loggers = {k: {'level': v} for k, v in levels.items()} + logging.config.dictConfig({ + 'version': 1, + 'loggers': loggers, + }) Collector(collector_config)