creating log file with Python logging module
Arulnambi Nandagoban
a.nandagoban at traxens.com
Tue Aug 5 05:43:35 EDT 2014
-----Message d'origine-----
De : Python-list
[mailto:python-list-bounces+a.nandagoban=traxens.com at python.org] De la part
de Peter Otten
Envoyé : Monday, August 4, 2014 4:03 PM
À : python-list at 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
More information about the Python-list
mailing list