import logging from logging.handlers import TimedRotatingFileHandler def init(baseFilename): logFilename = "test.log" print(f"Logging to {logFilename}.log") handler = TimedRotatingFileHandler(logFilename, when = "midnight", backupCount = 30, encoding = 'utf8') handler.setLevel(logging.DEBUG) handler.suffix = "%Y%m%d" # handler.extension = "log" <-- This is how I see this being fixed formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s [%(module)s:%(lineno)d]') handler.setFormatter(formatter) logging.basicConfig( handlers = [handler], format = '%(asctime)s %(levelname)s %(message)s [%(module)s:%(lineno)d]', level = logging.DEBUG, datefmt = '%Y-%m-%d %H:%M:%S') if __name__ == '__main__': init('testing') logging.error("ohai") logging.debug("ohai debug") logging.getLogger().handlers[0].doRollover() logging.error("ohai next day") logging.debug("ohai debug next day")