By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,035 Members | 1,388 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,035 IT Pros & Developers. It's quick & easy.

Re: Problem with TimedRotatingFileHandler

P: n/a
En Thu, 05 Jun 2008 04:14:07 -0300, <Do*****************>
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')
## Reference to the logger object
self.logger = logging.getLogger('FileLogger')

class MyInheritedError(MyError):
def __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
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

Jun 27 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.