Re: Problem with TimedRotatingFileHandler

Discussion in 'Python' started by Gabriel Genellina, Jun 11, 2008.

  1. En Thu, 05 Jun 2008 04:14:07 -0300, <>
    escribió:

    > Hi everyone
    >
    > I'm trying to use python's logging mechanism to write exception data
    > into a log file with the TimedRotatingFileHandler but the rotating of
    > the file is not working...
    > Here's a bit of sample code of what I'm doing (just the interessting
    > part of it ;-)):
    >
    > import logging
    > import logging.handlers as handlers
    > class MyError(Exception):
    >
    > fileName = os.path.join(os.path.dirname(__file__), 'Error.log')
    >
    > def __init__(self):
    > fileHandler =
    > handlers.TimedRotatingFileHandler(MyError.fileName, when='m',
    > interval=1, backupCount=1)
    > formatter = logging.Formatter('\n%(name)-12s: <%(asctime)s>
    > %(levelname)-8s %(message)s')
    > fileHandler.setFormatter(formatter)
    > logging.getLogger('').addHandler(fileHandler)
    > ## Reference to the logger object
    > self.logger = logging.getLogger('FileLogger')
    > self.logger.setLevel(logging.INFO)
    >
    > class MyInheritedError(MyError):
    > def __init__(self):
    > MyError.__init__(self)
    > self.logger.error("some stupid text :)")
    >
    > The error classes do write into the log file, however there's no
    > rotating. No new file is created (and old ones renamed) nor are there
    > any old log entries deleted/replaced...
    > Does anyone have any idea what I could be missing? Might it be a problem
    > due to the fact that these classes inherit from "Exception"?


    How do you use that class? raise MyInheritedError(...)? So you're creating
    the handler and logger and all that stuff when the exception is raised?
    Looks really really strange...
    Don't inherit from Exception - set up your handlers and loggers at the
    start of the application, then just call getLogger(...).error(some
    message).
    A logger called 'FileLogger' is suspicious too - *handlers* determine
    where the log info goes, or how it is processed; *loggers* determine the
    part of the application from which the the message originates (a subsystem
    like "database", or "client.db", or perhaps just the module name).

    --
    Gabriel Genellina
     
    Gabriel Genellina, Jun 11, 2008
    #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. Chris Shenton
    Replies:
    4
    Views:
    3,811
    Vinay Sajip
    Feb 23, 2007
  2. Lokesh
    Replies:
    5
    Views:
    1,425
    Vinay Sajip
    Aug 11, 2009
  3. Mike

    Problem problem problem :( Need Help

    Mike, May 7, 2004, in forum: ASP General
    Replies:
    2
    Views:
    581
    Bullschmidt
    May 11, 2004
  4. Dave Angel
    Replies:
    0
    Views:
    236
    Dave Angel
    Oct 24, 2012
  5. Vinay Sajip
    Replies:
    0
    Views:
    249
    Vinay Sajip
    Oct 24, 2012
Loading...

Share This Page