Skip to content

Commit 3c629e9

Browse files
author
Vladimir Kotal
committed
add log rotation
1 parent ee44d9f commit 3c629e9

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tools/sync/mirror.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import command
4242
from command import Command
4343
import logging
44+
from logging.handlers import RotatingFileHandler
4445
import tempfile
4546
import commands
4647
from commands import Commands, CommandsBase
@@ -79,6 +80,8 @@
7980
help='path to the Messages binary')
8081
parser.add_argument('-b', '--batch', action='store_true',
8182
help='batch mode - will log into a file')
83+
parser.add_argument('-B', '--backupcount', default=8,
84+
help='how many log files to keep around in batch mode')
8285
args = parser.parse_args()
8386

8487
if args.debug:
@@ -203,6 +206,16 @@
203206
level=logging.DEBUG if args.debug
204207
else logging.INFO)
205208
logger = logging.getLogger(os.path.basename(sys.argv[0]))
209+
handler = RotatingFileHandler(logfile, maxBytes=0,
210+
backupCount=args.backupcount)
211+
handler.doRollover()
212+
#
213+
# Technically, adding a handler to the logger is not necessary
214+
# since log rotation is done above using doRollover() however
215+
# it is done anyway in case the handler changes to use implicit
216+
# rotation in the future.
217+
#
218+
logger.addHandler(handler)
206219

207220
# We want this to be logged to the log file (if any).
208221
if project_config:

0 commit comments

Comments
 (0)