facundobatista at gmail.com
Thu Jun 13 19:41:16 MDT 2013
On Thu, Jun 13, 2013 at 7:14 PM, Glyph <glyph at twistedmatrix.com> wrote:
> For a long time, there's been consensus among at least a few core Twisted
> developers that log messages ought to be specified in terms of a format
> message and several relevant keyword arguments, so that tools can extract
> the values of the keyword arguments without parsing ad-hoc messages or using
> regexes. In other words, like this:
> log.msg(format="Foo happened. Relevant information includes: "
> "bar=%(bar)s baz=%(baz)s boz=%(boz)s",
> bar=bar, baz=baz, boz=boz)
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:
def msg(format_string, *args):
line = format_string % args
# something clever
No regexes involved, and very cheap in the case where it works.
And this is a personal opinion: the "working way" (where programmed
coded all ok) should be as cheap as possible. If something is wrong
with the logging line, it must not crash, and I don't care if it's
expensive, but that line will be fixed, and will work ok, and from
there to the future it will be cheap.
More information about the Twisted-Python