Skip to content
Snippets Groups Projects
Commit 10be0d6a authored by Georges Racinet's avatar Georges Racinet
Browse files

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.

```python
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.
parent cade6be9
No related branches found
No related tags found
1 merge request!65message: wrapper class for easy logging
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment