How to get structlog log level?

Question:

Is there a way to get the effective log level of a structlog logger? I want to do something like the following:

import structlog

logger = structlog.get_logger()

if logger.isEnabledFor(DEBUG):
    some_expensive_report()

I’m looking for something like isEnabledFor from the standard library logging module. Does such a thing exist?

Update: It looks like I can use logger.bind().isEnabledFor(), but only if I configure struct log with structlog.configure(wrapper_class=structlog.stdlib.BoundLogger). Is this the answer?

Asked By: itsadok

||

Answers:

As long as you use structlog’s standard library integration, you can use the method proxies that you’ve found yourself in the end. For structlog’s much faster native levels there’s no such functionality yet.

Answered By: hynek
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.