diff options
author | Egor Tensin <egor@tensin.name> | 2023-12-28 01:00:45 +0100 |
---|---|---|
committer | Egor Tensin <egor@tensin.name> | 2023-12-28 01:00:45 +0100 |
commit | a9ae33c4b9dbe566d2ada07affb8b5a135f9b6eb (patch) | |
tree | 72b47c96da722d5e034af789f4af432e3fdfa051 /test/py/lib/logging.py | |
parent | json: factor out json_object_put into json_free (diff) | |
download | cimple-a9ae33c4b9dbe566d2ada07affb8b5a135f9b6eb.tar.gz cimple-a9ae33c4b9dbe566d2ada07affb8b5a135f9b6eb.zip |
test/py/ -> test/src/
Diffstat (limited to 'test/py/lib/logging.py')
-rw-r--r-- | test/py/lib/logging.py | 45 |
1 files changed, 0 insertions, 45 deletions
diff --git a/test/py/lib/logging.py b/test/py/lib/logging.py deleted file mode 100644 index 663eb3a..0000000 --- a/test/py/lib/logging.py +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright (c) 2023 Egor Tensin <egor@tensin.name> -# This file is part of the "cimple" project. -# For details, see https://github.com/egor-tensin/cimple. -# Distributed under the MIT License. - -from contextlib import contextmanager -import logging -import logging.config -import logging.handlers -import multiprocessing as mp - - -@contextmanager -def child_logging_thread(): - # Delegating logging to the parent logger. - ctx = mp.get_context('spawn') - queue = ctx.Queue() - listener = logging.handlers.QueueListener(queue, logging.getLogger()) - listener.start() - try: - yield queue - finally: - listener.stop() - - -@contextmanager -def configure_logging_in_child(queue): - config = { - 'version': 1, - 'handlers': { - 'sink': { - 'class': 'logging.handlers.QueueHandler', - 'queue': queue, - }, - }, - 'root': { - 'handlers': ['sink'], - 'level': 'DEBUG', - }, - } - logging.config.dictConfig(config) - try: - yield - except Exception as e: - logging.exception(e) |