-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
38 lines (27 loc) · 1002 Bytes
/
test.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
37
38
import logging
import time
from logging.handlers import RotatingFileHandler
# ----------------------------------------------------------------------
def create_rotating_log(path):
"""
Creates a rotating log
"""
logger = logging.getLogger("Rotating Log")
logger.setLevel(logging.INFO)
loghandler = RotatingFileHandler('testLog', maxBytes=10000, backupCount=0)
logger.addHandler(loghandler)
print('created Log file')
logging.info('Logging starts ...')
logger = logging.getLogger("Rotating Log")
logger.setLevel(logging.INFO)
# add a rotating handler
handler = RotatingFileHandler(path, maxBytes=2000,
backupCount=0)
#logger.addHandler(handler)
for i in range(10):
logger.info("This is test log line %s" % i)
time.sleep(1.5)
# ----------------------------------------------------------------------
if __name__ == "__main__":
log_file = "test.log"
create_rotating_log(log_file)