I have a script which runs every day and is using TimedRoatingLogFileHandler of Python. Below is an excerpt from the code.
log = 'test.log' # Set up Log title
filename = '/var/log/' + log
handler = TimedRotatingFileHandler(filename, when="D", interval=1, backupCount=45)
formatter = logging.Formatter('%(asctime)s : %(name)s : %(levelname)s : %(message)s',
datefmt='%a, %d-%b-%Y %H:%M:%S')
handler.setFormatter(formatter)
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.addHandler(handler)
logger.info("Script execution started")
I am expecting a new logfile test.log gets created daily and the previous log will be moved to test.log.1 and test.log.2 etc.
Is my assumption correct? If so, why is it not happening? I can see yesterday's output in today's log still. Yesterday's log file is not moved to a different file as I was expecting. I am using Python 2.7 on a SUSE linux machine. I have checked the other threads but most of them don't contain any answers. Please let me know if you need some more details.