Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #75690

Re: creating log file with Python logging module

From Peter Otten <__peter__@web.de>
Subject Re: creating log file with Python logging module
Date 2014-08-04 15:24 +0200
Organization None
References <003d01cfafe2$e0668ac0$a133a040$@traxens.com>
Newsgroups comp.lang.python
Message-ID <mailman.12641.1407158720.18130.python-list@python.org> (permalink)

Show all headers | View raw


Arulnambi Nandagoban wrote:

> I am using logging module for my application to log all debug information.
> I configured it create a new log file every day with
> 
> "TimedRotatingFileHandler".  I display debug message in console as well.
> But I didn't see creation of new file. 

Is the script running continuously? You won't see a rollover if you restart 
it. Working example (with shorter time interval):

$ cat rollover.py 
import logging
import logging.handlers
import time

logger = logging.getLogger()

handler = logging.handlers.TimedRotatingFileHandler("logfile", when='S')

logger.addHandler(handler)
logger.setLevel(logging.INFO)

for i in range(100):
    logger.info("message #%s" % i)
    time.sleep(.1)

$ ls
rollover.py
$ python rollover.py 
$ ls
logfile                      logfile.2014-08-04_15-21-26
logfile.2014-08-04_15-21-21  logfile.2014-08-04_15-21-27
logfile.2014-08-04_15-21-22  logfile.2014-08-04_15-21-28
logfile.2014-08-04_15-21-23  logfile.2014-08-04_15-21-29
logfile.2014-08-04_15-21-24  logfile.2014-08-04_15-21-30
logfile.2014-08-04_15-21-25  rollover.py
$ cat logfile
message #93
message #94
message #95
message #96
message #97
message #98
message #99
$ 

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: creating log file with Python logging module Peter Otten <__peter__@web.de> - 2014-08-04 15:24 +0200

csiph-web