Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'handler': 0.05; 'subject:Python': 0.06; 'debug': 0.07; 'subject:file': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'restart': 0.09; 'subject:module': 0.09; 'python': 0.11; 'logger': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:log': 0.16; 'wrote:': 0.18; 'module': 0.19; 'example': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'file.': 0.24; 'script': 0.25; 'logging': 0.26; 'skip:" 20': 0.27; 'header:X-Complaints-To:1': 0.27; 'file': 0.32; 'running': 0.33; 'subject:with': 0.35; 'display': 0.35; 'but': 0.35; 'shorter': 0.36; "didn't": 0.36; 'application': 0.37; 'configured': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:l 50': 0.60; 'new': 0.61; 'day': 0.76 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: creating log file with Python logging module Date: Mon, 04 Aug 2014 15:24:54 +0200 Organization: None References: <003d01cfafe2$e0668ac0$a133a040$@traxens.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p57bdb6f6.dip0.t-ipconnect.de User-Agent: KNode/4.11.5 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 48 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1407158720 news.xs4all.nl 2893 [2001:888:2000:d::a6]:37742 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:75690 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 $