message: wrapper class for easy logging
With gRPC, the repr
of messages, notably Gitaly Requests
is made of multiple lines.
This is very bad for logging: a log should always be made of
a single line for:
- meaningful grepping
- detangling when several processes log to the same file
We want in particular service method to be able to log easily their incoming requests and/or more messages, but we want the formatting to be done only if the log is actually to be emitted (important to avoid debug logs to make production servers choke). This is usually achieved with the following pattern, because logging evaluation is inherently lazy.
logging.debug('the interesting object is %r', obj)
We could use extras, as hg-loggingmod
does for the repository,
but that is evaluated in the final formatting of the entire log
line, and requires to register a specific format, then a specific
handler to use it.
The provided solution (wrapping in a class), is not zero-cost, but is expected to be cheap enough for the time being.