Skip to content

Commit

Permalink
ENH: support dict log config (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
UranusSeven authored Oct 20, 2023
1 parent 30f4f4c commit d656b62
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/xoscar/backends/indigen/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ def _start_sub_pool(
logging_conf = conf["logging_conf"] or {}
if isinstance(logging_conf, configparser.RawConfigParser):
logging.config.fileConfig(logging_conf)
elif logging_conf.get("dict"):
logging.config.dictConfig(logging_conf["dict"])
elif logging_conf.get("file"):
logging.config.fileConfig(logging_conf["file"])
elif logging_conf.get("level"):
Expand Down
31 changes: 31 additions & 0 deletions python/xoscar/backends/indigen/tests/test_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,36 @@ def get_pid(self):
assert len({await ref.get_pid() for ref in refs}) == 2


# equivalent to test-logging.conf
DICT_CONFIG = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"formatter": {
"format": "%(asctime)s %(name)-12s %(process)d %(levelname)-8s %(message)s",
},
},
"handlers": {
"stream_handler": {
"class": "logging.StreamHandler",
"formatter": "formatter",
"stream": "ext://sys.stderr",
},
},
"loggers": {
"": {
"level": "WARN",
"handlers": ["stream_handler"],
},
"xoscar.backends.indigen.tests": {
"level": "DEBUG",
"handlers": ["stream_handler"],
"propagate": False,
},
},
}


@pytest.mark.asyncio
@pytest.mark.parametrize(
"logging_conf",
Expand All @@ -855,6 +885,7 @@ def get_pid(self):
},
{"level": logging.DEBUG},
{"level": logging.DEBUG, "format": "%(asctime)s %(message)s"},
{"dict": DICT_CONFIG},
],
)
async def test_logging_config(logging_conf):
Expand Down

0 comments on commit d656b62

Please sign in to comment.