Open thenumberouscode opened 1 year ago
As you said,
the name key has been set as myname as the logger name.
and it is ok behavior. I think the following names are reserved:
args
asctime
created
exc_info
filename
funcName
levelname
levelno
lineno
message
module
msecs
msg
name
pathname
process
processName
relativeCreated
stack_info
thread
threadName
https://docs.python.org/3/library/logging.html#logrecord-attributes
So, just pick another name for your extra!
emmm, I think it's inconvenient for users to use json formatter when there are so many reserve fields. As a formatter, it should format everything that user inputs.
Per the stack trace you provided, this error is being generated by logging
and not python-json-logger
.
Despite the package name, python-json-logger
is actually a logging.Formatter
and is only called from a logging.Handler
(which in turn must be attached to a logging.Logger
).
The reserved names are enforced by the default logging.Logger.makeRecord
implementation. If you'd like to be able to override any name using extra=
you'll need to create your own logging.Logger
subclass and override this method.
above code throws a exception which tell us that name has already been existed in LogRecord
output
Reading the related source code of logging, the name key has been set as myname as the logger name. so I am seriously curious about that if the way of using extra in my code is correct?
python json logger version python-json-logger 2.0.7 l