problems with logging module

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Jul 30 14:10:30 EDT 2007


En Mon, 30 Jul 2007 03:50:52 -0300, Alia Khouri <alia_khouri at yahoo.com>  
escribió:

> But I'm not letting the logging module off, it's still not the easiest
> or most intuitive module to work with.
>
> For example: a basic Log class that can be programatically configured
> would be quicker to work with then messing around with three different
> classes types if you want to get beyond basicConfig functionality:
> (Logger, handlers, formatters) To be able to do this would be nice:
>
> from logging import Log
>
> class MyClass:
>     def __init__(self, x):
>         self.x = x
>         self.log = Log(
>             level=logging.DEBUG,
>             format="%(asctime)s %(levelname)s: %(message)s",
>             datefmt = '%H:%M:%S',
>             filename='app.log',
>             filemode='a'
>         )

You are not going beyond basicConfig - I'd write the above as:

logging.basicConfig(...)

def __init__(self, x):
     self.x = x
     self.log = logging.getLogger("a.nice.name")

If you *do* need more than a handler, or different formatters for  
different loggers, then you must write your own setup anyway; perhaps  
using logging.config files, or perhaps writing your own code. I can't  
think of a simple and generic approach (beyond what basicConfig provides)  
but if you can write something that other people find useful, feel free to  
submit a patch.

-- 
Gabriel Genellina




More information about the Python-list mailing list