logging module: log file with datetime

  • Thread starter =?iso-8859-1?q?=C1lvaro_Nieto?=
  • Start date
?

=?iso-8859-1?q?=C1lvaro_Nieto?=

Hi

I have this logging config file;

====================================================================

[loggers]
keys=cdmto

[handlers]
keys=cdmtoHandler

[formatters]
keys=mtoFormatter

[logger_cdmto]
level=DEBUG
handlers=cdmtoHandler
qualname=cdmto
propagate=0

[handler_cdmtoHandler]
class=handlers.TimedRotatingFileHandler
level=DEBUG
formatter=mtoFormatter
args=('./Logs/cdmto.log',)

[formatter_mtoFormatter]
format=%(asctime)s %(levelname)-8s %(filename)s[%(lineno)d]: %
(message)s
datefmt=

====================================================================

How could I define a log file with datetime in his name?. Now the
name
for log file is './Logs/cdmto.log' and I'd like it would be './
Logs/cdmto_20070601.log',
for example.

Thanks.
 
V

Vinay Sajip

How could I define a log file with datetime in his name?. Now the
name
for log file is './Logs/cdmto.log' and I'd like it would be './
Logs/cdmto_20070601.log',
for example.

You can't do this just in the configuration - TimedRotatingFileHandler
automatically works out the filename in a predetermined manner when
doing rollover (dependent on whether it's doing rollovers daily,
hourly or whatever period). If you need more specific handling, you'll
need to write a subclass of TimedRotatingFileHandler which does what
you need.

Regards,

Vinay Sajip
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top