From c40c4cb08ad07fc70ab3882ea2896cf704124daa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Vask=C3=B3?= Date: Wed, 7 Jun 2023 23:01:21 +0200 Subject: [PATCH] refact(logging): wire in standard library logging --- unblob/logging.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/unblob/logging.py b/unblob/logging.py index a4c5667bb3..5c874257b1 100644 --- a/unblob/logging.py +++ b/unblob/logging.py @@ -90,6 +90,9 @@ def filter_(_logger, _method_name: str, event_dict: structlog.types.EventDict): def configure_logger(verbosity_level: int, extract_root: Path): log_level = logging.DEBUG if verbosity_level > 0 else logging.INFO processors = [ + structlog.stdlib.ProcessorFormatter.wrap_for_formatter, + ] + shared_processors = [ structlog.stdlib.add_log_level, filter_debug_logs(verbosity_level), structlog.processors.TimeStamper( @@ -100,14 +103,28 @@ def configure_logger(verbosity_level: int, extract_root: Path): structlog.processors.UnicodeDecoder(), structlog.processors.StackInfoRenderer(), structlog.processors.format_exc_info, - structlog.dev.ConsoleRenderer(colors=sys.stdout.isatty()), ] structlog.configure( wrapper_class=structlog.make_filtering_bound_logger(log_level), - processors=processors, + processors=shared_processors + processors, + logger_factory=structlog.stdlib.LoggerFactory(), + ) + + formatter = structlog.stdlib.ProcessorFormatter( + foreign_pre_chain=shared_processors, + processors=[ + structlog.stdlib.ProcessorFormatter.remove_processors_meta, + structlog.dev.ConsoleRenderer(colors=sys.stdout.isatty()), + ], ) + handler = logging.StreamHandler(sys.stdout) + handler.setFormatter(formatter) + root_logger = logging.getLogger() + root_logger.setLevel(log_level) + root_logger.addHandler(handler) + structlog.get_logger().debug( "Logging configured", vebosity_level=noformat(verbosity_level),