Closed jwuerzinger closed 4 months ago
After having had another look at structlog.stdlib.recreate_defaults
I believe I misunderstood what the function intends to do. I thought it would set log levels to the defaults that logging
would use, e.g.
import logging
print(logging.getLogger("asyncio"))
logs at WARNING level: <Logger asyncio (WARNING)>
. The recreate_defaults()
function without argument turns that into NOTSET:
import logging
import structlog
print(logging.getLogger("asyncio"))
structlog.stdlib.recreate_defaults()
print(logging.getLogger("asyncio"))
->
<Logger asyncio (WARNING)>
<Logger asyncio (NOTSET)>
I think this is consistent with what the documentation says. Apologies if that is only adding confusion to the discussion, I don't know a lot about structlog
and presumably just misunderstood the use of this function.
As y'all figured out, it does only the most basic configuration possible. I really do not want to interact with stdlib logging more than I have to here – it would make everything less predictable.
I am using uproot 5.3.7 with structlog 24.1.0 to open and inspect root files. I was getting some unexpected output when running:
Which produced this output:
The output can be suppressed by using
structlog.stdlib.recreate_defaults(log_level=logging.INFO)
or not callingrecreate_defaults()
.However, while using
logging
, this output is not produced with the default log level, but only if the log level is explicitly set toDEBUG
, i.e.:From what I gather from https://www.structlog.org/en/stable/api.html#structlog.stdlib.recreate_defaults, should the intended behaviour not be analogue to
logging
?Thanks a lot to @alexander-held for figuring this out!