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


Groups > comp.lang.python > #75687

creating log file with Python logging module

From "Arulnambi Nandagoban" <a.nandagoban@traxens.com>
Subject creating log file with Python logging module
Date 2014-08-04 14:51 +0200
Newsgroups comp.lang.python
Message-ID <mailman.12639.1407156882.18130.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

creating log file with Python logging module "Arulnambi Nandagoban" <a.nandagoban@traxens.com> - 2014-08-04 14:51 +0200

csiph-web