Example of how to use logging for both screen and file

Vinay Sajip vinay_sajip at yahoo.co.uk
Fri Oct 22 22:37:01 CEST 2004

[Ville Vainio]
> > I typically want to dump "info" level (and up) log information to
> > screen, and "debug" level (and up) to a log file for in-depth
> > analysis. This is for scripts, so date/time/severity information is
> > not wanted. I assumed such a simple use case would have an example in
> > the docs (py 2.4), but no luck.

> > Here's what worked for me:
[example snipped]

> > The example might not be ideal, but something like this should really
> > be in the module documentation.

Agreed. It's on my todo list to add more examples ...

> > The example config file mostly serves
> > to intimidate would-be users ("I need to do *that*?!?), and many of
> > them probably wouldn't want to introduce a third-party wrapper module
> > either (I think that should be the point of the standard logging
> > module after all).

A configuration file is not really needed for simple configurations.
For the simplest usage,  the minimal example at


should suffice.

> My idea now is to write a clean and simple wrapper for the logging
> module, using sensible defaults, and exposing simple methods.
> Something like (still pseudo-code):
[code snipped]

Take a look at the link above. You cannot code logging much more
simply than that.

Documentation can always be improved. Patches are always welcome! I
will look at adding Ville's simple use case to the documentation as my
next documentation activity.


Vinay Sajip

More information about the Python-list mailing list