forked from theQRL/QRL
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlogger.py
More file actions
36 lines (28 loc) · 995 Bytes
/
logger.py
File metadata and controls
36 lines (28 loc) · 995 Bytes
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
# Logging file, must be imported by other programs,
# in order to log informations into log file
__author__ = 'cyyber'
import logging
import sys
from logging.handlers import RotatingFileHandler
log_formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(funcName)s(%(lineno)d) - %(message)s')
no_formatter = logging.Formatter('%(message)s')
logFileName = 'qrl.log'
my_handler = RotatingFileHandler(logFileName, mode='a', maxBytes=100*1024*1024,
backupCount=2, encoding=None, delay=0)
my_handler.setFormatter(log_formatter)
my_handler.setLevel(logging.INFO)
class PrintHelper:
def __init__(self, logger):
self.logger = logger
def printL(self, data, enableLogging=True):
if hasattr(data,'__iter__'):
data = map(str, data)
data = " ".join(data)
if enableLogging:
self.logger.info(data)
print data
def getLogger(name):
logger = logging.getLogger(name)
logger.setLevel(logging.INFO)
logger.addHandler(my_handler)
return logger