Logging within a class

Joseph L. Casale jcasale at activenetwerx.com
Sun Feb 10 20:26:52 EST 2013


Within __init__ I setup a log with self.log = logging.getLogger('foo') then add a
console and filehandler which requires the formatting to be specified. There a few
methods I setup a local log object by calling getChild against the global log object.


This works fine until I need to adjust the formatter for a few. With this style, I need
to redefine the handlers, so basically setup logging again.


I tried to get around this by using basicConfig and simply re-specifying format inside
the few methods, but it didn't work.


How does one accomplish this most elegantly so I can define one log instance with
the appropriate general console and file handlers in my class, then simply override
the formatter for both handlers they use in a couple methods?


Thanks!
jlc


More information about the Python-list mailing list