Skip to content

Commit

Permalink
configuration: add logging_levels section
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
olaf-mandel committed Oct 5, 2024
1 parent fb5a956 commit 23be164
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ collector_opts:
blacklist:
- docker0
- lo
logging_levels:
root: INFO
foomodule.barcollector: WARNING
```
### Start-up Configuration
Expand Down
2 changes: 2 additions & 0 deletions p3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ collector_opts:
blacklist:
- docker0
- lo
logging_levels:
root: INFO
9 changes: 8 additions & 1 deletion p3exporter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from wsgiref.simple_server import make_server

import yaml
import logging
import logging.config
import os
import signal
import sys
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 23be164

Please sign in to comment.