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


Groups > comp.lang.python > #75690 > unrolled thread

Re: creating log file with Python logging module

Started byPeter Otten <__peter__@web.de>
First post2014-08-04 15:24 +0200
Last post2014-08-04 15:24 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#75690 — Re: creating log file with Python logging module

FromPeter Otten <__peter__@web.de>
Date2014-08-04 15:24 +0200
SubjectRe: creating log file with Python logging module
Message-ID<mailman.12641.1407158720.18130.python-list@python.org>
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
$ 

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web