1

im using structlog, and im configuring it to use the filter_by_level processor:

    structlog.configure(
    processors = [
        structlog.stdlib.add_log_level,             
        structlog.stdlib.add_log_level_number,      
        structlog.processors.format_exc_info,       
        structlog.stdlib.filter_by_level,
        structlog.processors.JSONRenderer(),        
    ],
    wrapper_class = structlog.stdlib.BoundLogger,
    logger_factory = structlog.PrintLoggerFactory(),
    cache_logger_on_first_use=True,
)

But when i call logger.setLevel(level)

im getting "PrintLogger has no attribute setLevel".

should i use a different logger factory? i dont see any other loggers under "_loggers.py"

1 Answers1

0

Yes, if you want to use standard library methods of the returned logger, you have to use structlog.stdlib.LoggerFactory().

Your current configuration doesn’t use standard library for output.

See https://www.structlog.org/en/stable/standard-library.html#rendering-using-logging-based-formatters for a simple yet complete example.

hynek
  • 3,647
  • 1
  • 18
  • 26
  • using it does give me the option to call setLevel, but when running my app nothing from the log is being printed to stdout anymore (compared to when i used the PrintLogger) – Tamir Gefen Oct 11 '21 at 14:21
  • You probably haven't configured standard library logging: https://www.structlog.org/en/stable/standard-library.html#just-enough-logging – hynek Oct 12 '21 at 14:36