Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python
- # This script is a simple alternative for rotating e.g. TYPO3 application log files
- # whenever the host can't handle those log files from OS level (e.g. on shared/managed hosting environments)
- #
- #
- # It's intended to start the script on a regular base via crontab like:
- #
- # Argument 1: path to logfile (string)
- # Argument 2: backupCount (int)
- #
- # 0 1 * * * /path/to/releases/current/bin/logrotate.py /path/to/releases/current/var/log/typo3/typo3.log 4 > /dev/null
- # 0 1 * * * /path/to/releases/current/bin/logrotate.py /path/to/releases/current/var/log/typo3/solr.log 4 > /dev/null
- #
- #
- 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=104857600,
- backupCount=backupCount,
- encoding=None,
- delay=False
- )
- handler.doRollover()
Advertisement
Add Comment
Please, Sign In to add comment