creating log file with Python logging module
Arulnambi Nandagoban
a.nandagoban at traxens.com
Mon Aug 4 08:51:57 EDT 2014
Hello all,
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. Can someone help me to sort out this
problem. Following is config code:
import logging
from logging.handlers import TimedRotatingFileHandler
Ffilename = os.path.join(dir_path, 'Pyserverlog')
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')
logger.addHandler(hdlr)
# define a Handler which writes INFO messages or higher to the sys.stderr
console = logging.StreamHandler()
console.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s -
%(message)s')
# tell the handler to use this format
console.setFormatter(formatter)
# add the handler to the root logger
logging.getLogger('').addHandler(console)
--
nambi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140804/7a38454e/attachment.html>
More information about the Python-list
mailing list