[Twisted-Python] logging

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Fri Jun 14 15:47:56 MDT 2013

On 07:45 pm, radix at twistedmatrix.com wrote:
>On Fri, Jun 14, 2013 at 1:41 AM, Jamu Kakar <jkakar at kakar.ca> wrote:
>>On Thu, Jun 13, 2013 at 6:41 PM, Facundo Batista
>><facundobatista at gmail.com> wrote:
>>>Mmm... which is the problem with doing:
>>>log.msg("Foo happened. Relevant information includes: "
>>>              "bar=%s baz=%s boz=%s", bar, baz, boz)
>>>Is way more readable, and in the practice the code will just need to
>>>do something like:
>>The example above could be written in a logfmt-compatible way as:
>>   log.msg("message=Foo happened bar=%s baz=%s boz=%s", bar, baz, boz)
>>This is as readable as what you have above while being a touch easier
>>to parse.  The main point that logs are data and should emitted in a
>>way that makes consuming them easy is a good one regardless of the
>>format you choose.  I do wonder if logfmt is unnecessary and if simply
>>dumping JSON objects would be just as good... logfmt is slightly
>>prettier but the JSON approach has the advantage of having a parser
>>available in basically every language anyone would ever care about.
>I think both of these should be avoided because they require the user
>to specify string interpolation themselves. I'd prefer to avoid that
>entirely, by default.
>log.msg("Foo happened**", bar=bar, baz=baz, boz=boz)
>This is better because:
>1. it keeps the data structured
>2. it is a lot less typing
>** I would prefer this part to be "foo", but I'll keep these
>discussions separate :)

I think that I agree with this, except I wonder if you could supply some 
more realistic examples here.  Let's say I have a somewhat complex 
50kloc application with a log event emitted around once every 10 lines.

After I use up "foo", "bar", "baz", and "quux" I start having to refer 
to the hacker dictionary.  This doesn't get me very close to the 5000 
event identifiers I'll need.  How does someone come up with this in the 
real world?


More information about the Twisted-Python mailing list