Skip to content

Commit 3b3e866

Browse files
committed
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.
1 parent fb5a956 commit 3b3e866

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ collector_opts:
113113
blacklist:
114114
- docker0
115115
- lo
116+
logging_levels:
117+
root: INFO
118+
foomodule.barcollector: WARNING
116119
```
117120
118121
### Start-up Configuration

p3.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ collector_opts:
99
blacklist:
1010
- docker0
1111
- lo
12+
logging_levels:
13+
root: INFO

p3exporter/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from wsgiref.simple_server import make_server
44

55
import yaml
6-
import logging
6+
import logging.config
77
import os
88
import signal
99
import sys
@@ -41,6 +41,13 @@ def main():
4141
with open(args.config, 'r') as config_file:
4242
cfg = yaml.load(config_file, Loader=yaml.SafeLoader)
4343
collector_config = CollectorConfig(**cfg)
44+
if isinstance(cfg.get('logging_levels'), dict):
45+
levels = cfg['logging_levels']
46+
loggers = {k: {'level': v} for k, v in levels.items()}
47+
logging.config.dictConfig({
48+
'version': 1,
49+
'loggers': loggers,
50+
})
4451

4552
Collector(collector_config)
4653

0 commit comments

Comments
 (0)