Closed symbolix closed 8 years ago
I also wrote a simple formatter that works together with logaware
, so that I can change the look of how the contextual information is displayed:
class ContextLogFormatter(logging.Formatter):
"""
Flattens the contextual information into a string that later can be mapped
to the %(context)s slot assigned by the format string.
"""
def format(self, record):
if record.meta:
if 'context' in record.meta:
record.context = '{}={}'.format('context', record.meta.get('context', None))
else:
record.context = 'context=None'
# Return the result.
return super(ContextLogFormatter, self).format(record)
Then I just attach that as a normal formatter. And it works. I hope that is how I should be doing this. Thanks.
Do not worry about this issue. I can see that logaware
is taking care of this when internally requesting the logger.
Yep. You can just always import log
and use it from log = MetaAwareLogger(lambda: meta.get_meta())
. That's part of the purpose of logaware
-- never having to use a module specific logger.
Hi,
I have been doing a bit of testing and I think I am getting pretty comfortable with the API of logaware. The examples and our discussions in the previous issues was really helpful. Thank you very much for that.
Right now, I am trying to minimise the boiler plate stuff required to get the logger working across an application and any modules. It is already very efficient and it seems like it is all working very well.
So this is what I have in my main app:
The question is, in a module that is also required to use the same logger, do we need to do anything special? For example, this is how I have things set-up in a module:
And I am getting this:
Which is really working well for me. So usually, with the native logging it would be something like:
at the start of the main application and then in the module:
and the logging will be simply connecting to the same logger. It seems like we do not need that with the
logaware
module? How much of the initiallogaware
boiler plate code do I need at the start of a module?Thanks.