Logging within a class

Discussion in 'Python' started by Joseph L. Casale, Feb 11, 2013.

  1. 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 globallog object.


    This works fine until I need to adjust the formatter for a few. With thisstyle, 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
    Joseph L. Casale, Feb 11, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Siegl
    Replies:
    0
    Views:
    940
    Stefan Siegl
    Aug 27, 2003
  2. janne
    Replies:
    0
    Views:
    9,447
    janne
    Sep 10, 2004
  3. Christoph Haas
    Replies:
    0
    Views:
    431
    Christoph Haas
    Jun 12, 2006
  4. Christoph Haas
    Replies:
    1
    Views:
    441
    Vinay Sajip
    Jun 14, 2006
  5. johnny
    Replies:
    1
    Views:
    623
    Dennis Lee Bieber
    Dec 12, 2006
Loading...

Share This Page