How do I get logger to delete existing log file before writing to it again?
Try this:
filehandler_dbg = logging.FileHandler(
logger.name + '-debug.log',
mode='w')
to open the filename in write
mode instead of append
mode, clobbering logger.name
More information: logging.FileHandler docs, open()
and list of modes
If you are using any external configuration file then pass 'w' for write mode in args of the handler.
[loggers]
keys=root
[logger_root]
level=DEBUG
handlers=file_handler
[handlers]
keys=file_handler
[handler_file_handler]
class=FileHandler
formatter=formatter
args=("../log/test" + time.strftime("%%Y%%m%%d%%H%%M%%S") + '.log', 'w')
[formatters]
keys=formatter
[formatter_formatter]
format=%(asctime)s %(levelname)-5s [%(module)s] %(message)s