-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.py
36 lines (30 loc) · 928 Bytes
/
log.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
'''Class for handling the logs '''
import logging
from logging.handlers import RotatingFileHandler
class Log():
def __init__(self, logfile):
self._logger = logging.getLogger("Rotating Log")
self._logger.setLevel(logging.INFO)
loghandler = RotatingFileHandler(logfile, maxBytes=10000, backupCount=0)
self._logger.addHandler(loghandler)
def log(self, record):
if len(record) > 0:
self._logger.info(record)
'''
from flask_restful import Resource
logfile = "helloworldlogs.log"
count = dict()
class GetLog(Resource):
def get(self):
t = ''
with open("helloworldlogs.log") as f:
t = f.readlines()
for i in t:
ip = i.split('|')[0].strip()
count[ip] = count.get(ip, 0) + 1
print(count)
return t
'''
def get_circular_logger(filename):
logger = Log(filename)
return logger