Skip to content

Commit

Permalink
refact(logging): wire in standard library logging
Browse files Browse the repository at this point in the history
  • Loading branch information
László Vaskó committed Jun 7, 2023
1 parent 758acaa commit c40c4cb
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions unblob/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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),
Expand Down

0 comments on commit c40c4cb

Please sign in to comment.