Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75725
| From | "Arulnambi Nandagoban" <a.nandagoban@traxens.com> |
|---|---|
| References | <003d01cfafe2$e0668ac0$a133a040$@traxens.com> <lro1j7$r2d$1@ger.gmane.org> <lro39e$f7u$1@ger.gmane.org> <lro3rl$pdb$1@ger.gmane.org> |
| Subject | RE: creating log file with Python logging module |
| Date | 2014-08-05 11:43 +0200 |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.12663.1407231981.18130.python-list@python.org> (permalink) |
-----Message d'origine-----
De : Python-list
[mailto:python-list-bounces+a.nandagoban=traxens.com@python.org] De la part
de Peter Otten
Envoyé : Monday, August 4, 2014 4:03 PM
À : python-list@python.org
Objet : Re: creating log file with Python logging module
Peter Otten wrote:
> Peter Otten wrote:
>
>> You won't see a rollover if you restart it.
>
> Sorry, I tried it and the above statement is wrong.
[Arulnambi Nandagoban]
> logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s -
> %(message)s', datefmt='%a, %d %b %Y %H:%M:%S', level = logging.DEBUG,
> filename=Ffilename, filemode='w')
>
> logger = logging.getLogger(__name__)
>
> hdlr = TimedRotatingFileHandler(Ffilename, when='midnight')
My alternative theory about what might be going wrong: you are using the
same file in logging.basicConfig() and the TimedRotatingFileHandler.
But I cannot replicate the problem on my (linux) system.
--
https://mail.python.org/mailman/listinfo/python-list
Hello,
Thank you for response !!!
-- Config.py:
import logging
from logging.handlers import TimedRotatingFileHandler
import os
import time
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s -
%(message)s', datefmt='%a, %d %b %Y %H:%M:%S')
logHandler = TimedRotatingFileHandler(Ffilename,when="D")
logFormatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s -
%(message)s', datefmt='%a, %d %b %Y %H:%M:%S')
logHandler.setFormatter( logFormatter )
logger = logging.getLogger(__name__ )
logger.addHandler( logHandler )
logger.setLevel( logging.DEBUG )
The above code works according to my need that is,
- print log in console as well as save log in a file every day
By adding logging.basicConfig, log is printed in both console and saved in
log file.
--
nambi
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
RE: creating log file with Python logging module "Arulnambi Nandagoban" <a.nandagoban@traxens.com> - 2014-08-05 11:43 +0200
csiph-web