import logging import logging.handlers formatter = logging.Formatter("%(asctime)s - %(levelname)-1s - %(name)s - %(message)s") loggingLevel = logging.DEBUG # Setting up rotating file handler logFilename = 'c:\Temp\log.txt' maxFileSize = 100 # Maximum file size in bytes noOfRotatingFiles = 5 # Number of rotating files rotFileHandler = logging.handlers.RotatingFileHandler(logFilename, maxBytes = maxFileSize, backupCount= noOfRotatingFiles) rotFileHandler.setFormatter(formatter) rotFileHandler.setLevel(loggingLevel) logger = logging.getLogger('LogTest') logger.setLevel(logging.DEBUG) logger.addHandler(rotFileHandler) for i in range(20): logger.info("Message # %d" %i) logging.shutdown()