Skip to content

Instantly share code, notes, and snippets.

@plopp
Created February 28, 2017 22:03
Show Gist options
  • Save plopp/29a06ab3886304a0828679a580fb9508 to your computer and use it in GitHub Desktop.
Save plopp/29a06ab3886304a0828679a580fb9508 to your computer and use it in GitHub Desktop.
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