Created
February 28, 2017 22:03
-
-
Save plopp/29a06ab3886304a0828679a580fb9508 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import time | |
from logging.handlers import TimedRotatingFileHandler | |
#---------------------------------------------------------------------- | |
def create_timed_rotating_log(path): | |
"""""" | |
logger = logging.getLogger("Rotating Log") | |
logger.setLevel(logging.INFO) | |
handler = TimedRotatingFileHandler(path, | |
when="m", | |
interval=1, | |
backupCount=5) | |
logger.addHandler(handler) | |
for i in range(500): | |
logger.info("This is a test!") | |
time.sleep(1) | |
#---------------------------------------------------------------------- | |
if __name__ == "__main__": | |
log_file = "timed_test.log" | |
create_timed_rotating_log(log_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment