Logging Help

Robert Rawlins - Think Blue robert.rawlins at thinkbluemedia.co.uk
Wed Jan 2 09:48:30 EST 2008


Hello Guys,

 

I'm having a little trouble modifying my logging so that the log files are
rotated. I'm using the standard python logging module and can find some
decent documentation on how to create and add a rotatingFileHandler to my
logger but I've been unable to find out how to disable the standard File
handler.

 

I currently create my logger like this:

 

logging.basicConfig(level=logging.DEBUG,

                    format='%(asctime)s %(levelname)-8s %(message)s',

                    datefmt='%a, %d %b %Y %H:%M:%S',

                    filename='/var/log/ThinkBlue.log',

                    filemode='a')

 

What's the best way to change this so that ThinkBlue.log grows no larger
than let's say 5mb and that we keep 5 archives of the log, I know I can
create a new handler and add it to the logger like this:

 

newlevel = logging.handlers.RotatingFileHandler('/var/log/ThinkBlue.log',

                                                'a',

                                                5000,

                                                5)

 

logging.getLogger('').addHandler(newlevel)

 

But fear this will mean I'm writing to the log file twice, is that right? I
need some help, am I going about this the correct way of is there a better
way of doing this?

 

Cheers guys,

 

Rob

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080102/73bf5866/attachment.html>


More information about the Python-list mailing list