forked from pmoogi-redhat/logloss-benchmarking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file-rotate-test-basedon-maxsize-of-logfile.py
36 lines (30 loc) · 1.14 KB
/
file-rotate-test-basedon-maxsize-of-logfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import logging
import logging.handlers
import time
import sys
def payload_fixed(size):
return 'x' * size
def main():
#just to limit upper bound to log lines generation to 10 million lines
MAXLOGLINES=10000000
maxsize=int(sys.argv[1])
rateofloglineG=float(sys.argv[2])
logfilename=sys.argv[3]
backupFiles=int(sys.argv[4])
print("maxsize of log file",maxsize)
print("gap between two log lines",rateofloglineG)
log = logging.getLogger(__name__)
fsize=1024
payloadfixedsize=payload_fixed(fsize)
#class logging.handlers.RotatingFileHandler(filename, mode='a', maxBytes=0, backupCount=0, encoding=None, delay=False, errors=None)
log_formatter = logging.Formatter('[%(asctime)s][%(levelname)s](%(threadName)-10s) %(message)s')
trfh = logging.handlers.RotatingFileHandler(logfilename, mode='a', encoding='utf-8', maxBytes=maxsize, backupCount=backupFiles,delay=False)
trfh.setFormatter(log_formatter)
log.addHandler(trfh)
count=0
while count < MAXLOGLINES :
time.sleep(rateofloglineG)
count=count+1
log.warning(payloadfixedsize + ':' + str(count))
return
main()