Skip to content

Commit

Permalink
Fix logging when using as library
Browse files Browse the repository at this point in the history
When unblob is used as a library, the structlog may already be
configured as the end-user likes. In this case:
    1) We don't need to configure it again with our CLI config.
    2) We still need to apply the "pretty_print_types" processor to the
processor chain, so our types will be printed nicely.
We add this to the begining of the processor chain, because
    - It is lightweight
    - At the end of the processor chain must be some render, which will
convert the whole event_dict to str, and usually before the renderer,
there are various amount of error / exception formatters.
  • Loading branch information
kukovecz committed Dec 14, 2021
1 parent d7cbdf5 commit f3cb0fe
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions unblob/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ def convert_type(logger, method_name: str, event_dict: structlog.types.EventDict


def configure_logger(verbose: bool, extract_root: Path):
if structlog.is_configured:
# If used as a library, with already configured structlog, we still need our types to be prettyly printed
processors = structlog.get_config().get("processors", [])
processors.insert(0, pretty_print_types(extract_root))
structlog.configure(processors=processors)
return

log_level = logging.DEBUG if verbose else logging.INFO
processors = [
structlog.stdlib.add_log_level,
Expand Down

0 comments on commit f3cb0fe

Please sign in to comment.