It seems to me that is somewhat of a design flaw.
Say I have a number of threads, each serving a client connection. Now when
the thread starts, I can say:
logbook.Processor(self.extra_info).push_thread()
This processor would add the user id to the record. Now, in various places
within the thread, I can simply call the logbook log functions, with the
user id always being automatically injected.
The problem is getting the extra info formatted. The handler that I setup
at the application-level knows nothing of these specific extra fields of a
sub-component of the app, nor should it.
I am considering attaching a handler to the logger that only reformats the
message:
class ExtraFormattingHandler(logbook.Handler):
def __init__(self):
super(ExtraFormattingHandler, self).__init__(bubble=True)
def emit(self, record):
record.message = '....'
log = logbook.Logger(__name__)
log.handlers.append(ExtraFormattingHandler())
However, that feels a bit hacky. Is there a better way to deal with this?