Open symbolix opened 7 years ago
To illustrate this with a simple example:
This code:
# Initialise logger.
log = logging.getLogger()
log.setLevel(logging.DEBUG)
# Define a format.
format_template = u'%(message)s [%(event)s]'
formatter = logging.Formatter(format_template)
# Create a handler.
ch = logging.StreamHandler()
ch.setFormatter(formatter)
ch.setLevel(logging.DEBUG)
# Add the handler to the logger
log.addHandler(ch)
log.warning(" Captured event is:", extra={'event':'buffer'})
Will produce this output:
Captured event is: [buffer]
But with logaware
, this would fail as the extra {}
bit is stored inside a dictionary called data {}
. So it is not exactly compliant with the standard logging
module. If it is a feature, please ignore me. Thanks.
I suppose it is a bug. Since logaware has metadata, extra might not be needed anymore.
Hi,
While investigating the mechanics of the stdlib's
logging
module, I had a chance to peak into how the internal_log()
method is working and how theextra={}
is handled.I have noticed that the
MetaAwareLogger
that in return inherits fromAwareLogger
does not exactly respect the process of passing in anextra
dictionary with the log message. I wonder if this is an issue or a feature?Would fail with a formatter such as
[%s(meta)s] [%s(event)s]
as internally the
extra
is stored inside a nested dictionarydata {}
. So there are two main dictionariesmeta {}
anddata {}
.meta {}
makes sense, but to be able to access the contents ofdata {}
one would need a customFormatter
to display data['extra'] with the above specified formatter template. To get his:Just checking. Thanks.