[Chicago] Taking Some Pain Out Of Python Logging

Skip Montanaro skip at pobox.com
Thu Mar 7 16:01:35 CET 2013


> ....Or, How I learned to stop worrying and love syslog.  :-)

> I kinda know where all the [flawed] reinventions of these wheels are
> coming from....

Java? :-)

>   http://hynek.me/articles/taking-some-pain-out-of-python-logging/

At work we've used the stdlib logger in the platform I work on for
quite awhile.  We log heavily, and were always disappointed in logging
performance.  It was mostly caused by all the features baked into the
stdlib logger which we never used (I'm sure inherited from log4j or
whatever its logical parent was).  Over time we tried various things,
including inlining a stripped down __init__, threading the loggers,
rewriting things in C++, yadda, yadda, yadda.  A few months ago I
broke down and wrote a very simple class which implements the basic
logging API, can only log in one format, and only uses those features
we actually need.  The platform is very mature, so I'm not worried
about ever needing the log the thread name, or need to format messages
in all sorts of strange and wonderful ways, for example.  It's fast,
hasn't got any threading issues (*), and we will probably break the
disk drive with our log messages before the logger craps out.  (Yes,
we do our own log file rotation.)

Skip

(*) When you think about it, running a logger in its own thread is
probably not that useful.  The OS probably does a much better job of
scheduling writes to disk, and to switch threads you have to go
through the kernel anyway. The threaded logger has more trips through
the kernel to write to the file, once to switch to the logger thread,
once to write the bits. Just write the damn message and be done with
it...


More information about the Chicago mailing list