Closed oscaroteromar closed 4 months ago
I believe the information you're looking for should be in event_dict["_record"]
?
Thanks for the response! It's true that I can access the log level as you say
(Pdb) a
self = <logging_config.DummyProcessor object at 0x108a5c490>
logger = None
method_name = 'debug'
event_dict = {'event': 'A log test from structlog.', '_record': <LogRecord: testing_sructlog, 10, /Users/<...>/structlog-issue/main.py, 41, "A log test from structlog.">, '_from_structlog': False}
(Pdb) p event_dict['_record'].levelno
10
(Pdb) p event_dict['_record'].levelname
'DEBUG'
(Pdb)
I'll use this for the workaround, thank you!
Describe the bug
I have an hybrid configuration which uses structlog loggers and Python's logging loggers. I have applied different processors, some custom, in order to format my logs. In one of my custom processors, I want to do some formatting depending on the log level set in the configuration. For this, I access the first argument
logger
that arrives to the processor, like:Here comes the problem: when the logger that emits the log is a structlog logger (
logger = structlog.stdlib.get_logger("testing_sructlog")
), I have no problem since the given object is<_FixedFindCallerLogger testing_sructlog (DEBUG)>
, however, when the logger comes from Python's logging, the logger argument isNone
. I'd like to get a valid object always forlogger
in order to access the log level and proceed.To reproduce
Please, check the following repository which contains an emulation of my real problem in order to reproduce it.
Current output:
Expected output (more or less):
Versions
Python 3.10.13 Structlog 24.1.0
Is this a bug or is it an intended behaviour?
Thank you in advance!