-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
fb5a956
commit d2bf861
Showing
4 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ collector_opts: | |
blacklist: | ||
- docker0 | ||
- lo | ||
logging_levels: | ||
root: INFO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from p3exporter import setup_logging | ||
import logging | ||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize("cfg_levels,expected", [ | ||
(None, [logging.NOTSET, logging.NOTSET, logging.NOTSET]), | ||
("Not a dict", [logging.NOTSET, logging.NOTSET, logging.NOTSET]), | ||
({"": "INFO", "foo": "DEBUG"}, [logging.INFO, logging.DEBUG, logging.NOTSET]), | ||
({"root": "WARNING", "bar": "CRITICAL"}, [logging.WARNING, logging.NOTSET, logging.CRITICAL]), | ||
({"foo": 10, "bar": 20}, [logging.NOTSET, logging.DEBUG, logging.INFO]), | ||
]) | ||
def test_logging_levels(cfg_levels, expected): | ||
loggers = ["", "foo", "bar"] | ||
|
||
# GIVEN a clean slate of uninitialized logging-levels | ||
for lg in loggers: | ||
logging.getLogger(lg).setLevel(logging.NOTSET) | ||
|
||
# AND an input config-dictionary | ||
cfg = { | ||
"exporter_name": "Test only", | ||
"collectors": [], | ||
"collector_opts": {}, | ||
} | ||
if cfg_levels is not None: | ||
cfg["logging_levels"] = cfg_levels | ||
|
||
# WHEN calling setup_logging() | ||
setup_logging(cfg) | ||
|
||
# THEN the logging-levels should get changed to the expected | ||
for i, lg in enumerate(loggers): | ||
assert logging.getLogger(lg).level == expected[i] |