Created
October 4, 2021 10:13
-
-
Save jonaseberle/a5ddb272d50ca8a25a7ed72f5b0d8ab4 to your computer and use it in GitHub Desktop.
Python logrotate
This file contains hidden or 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
#! /usr/bin/env python | |
import sys | |
import logging.handlers | |
try: | |
logfile = sys.argv[1] | |
except: | |
print("param 1: logfile") | |
sys.exit(1) | |
try: | |
backupCount = int(sys.argv[2]) | |
except: | |
print("param 2: backup count") | |
sys.exit(1) | |
handler = logging.handlers.RotatingFileHandler( | |
logfile, | |
mode='a', | |
maxBytes=0, | |
backupCount=backupCount, | |
encoding=None, | |
delay=False | |
) | |
handler.doRollover() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment