2014-03-03 01:18:51 +01:00
|
|
|
import logging
|
|
|
|
from logging.handlers import RotatingFileHandler
|
2014-03-02 22:57:48 +01:00
|
|
|
import time
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
class Log(object):
|
2014-03-03 12:10:06 +01:00
|
|
|
def __init__(self) :
|
2014-03-03 13:26:40 +01:00
|
|
|
|
2014-03-03 13:38:00 +01:00
|
|
|
logging.addLevelName(25, "SUCCESS")
|
2014-03-03 13:23:52 +01:00
|
|
|
|
2014-03-03 13:39:07 +01:00
|
|
|
self.logger = logging.getLogger()
|
2014-03-03 12:10:06 +01:00
|
|
|
self.logger.setLevel(logging.DEBUG)
|
2014-03-03 13:13:00 +01:00
|
|
|
formatter = logging.Formatter('%(asctime)-15s :: %(levelname)s :: %(message)s')
|
2014-03-03 13:23:52 +01:00
|
|
|
|
2014-03-03 12:10:06 +01:00
|
|
|
file_handler = RotatingFileHandler('activity.log', 'a', 1000000, 1)
|
|
|
|
file_handler.setLevel(logging.DEBUG)
|
|
|
|
file_handler.setFormatter(formatter)
|
|
|
|
self.logger.addHandler(file_handler)
|
|
|
|
|
2014-03-03 13:13:00 +01:00
|
|
|
file_handler_error = RotatingFileHandler('error.log', 'a', 1000000, 1)
|
|
|
|
file_handler_error.setLevel(logging.ERROR)
|
|
|
|
file_handler_error.setFormatter(formatter)
|
|
|
|
self.logger.addHandler(file_handler_error)
|
|
|
|
|
2014-03-03 01:43:37 +01:00
|
|
|
def enregDansLog(self,pLog,pMsg,pIP):
|
|
|
|
with open("fichier/log", "a") as dest :
|
|
|
|
d = datetime.now().strftime("%c")
|
|
|
|
dest.write("%s,%s,%s,%s\n" % (d,pLog,pMsg,pIP))
|
2014-03-03 01:18:51 +01:00
|
|
|
|
2014-03-03 12:10:06 +01:00
|
|
|
|
2014-03-03 12:11:19 +01:00
|
|
|
def printL(self,pMsg,pLvl):
|
2014-03-03 12:17:14 +01:00
|
|
|
self.logger.log(pLvl,pMsg)
|
2014-03-03 12:12:19 +01:00
|
|
|
if pLvl == 10 :
|
2014-03-03 13:55:30 +01:00
|
|
|
print bcolors.DEBUG
|
2014-03-03 12:11:19 +01:00
|
|
|
elif pLvl == 20 :
|
2014-03-03 13:55:30 +01:00
|
|
|
print bcolors.INFO
|
2014-03-03 13:20:16 +01:00
|
|
|
elif pLvl == 25 :
|
2014-03-03 13:55:30 +01:00
|
|
|
print bcolors.SUCCESS
|
2014-03-03 12:11:19 +01:00
|
|
|
elif pLvl == 30 :
|
2014-03-03 13:55:30 +01:00
|
|
|
print bcolors.WARNING
|
2014-03-03 12:11:19 +01:00
|
|
|
elif pLvl == 40 :
|
2014-03-03 13:55:30 +01:00
|
|
|
print bcolors.FAIL
|
2014-03-03 12:11:19 +01:00
|
|
|
print pMsg
|
2014-03-03 13:55:30 +01:00
|
|
|
print bcolors.ENDC
|
2014-03-03 12:10:06 +01:00
|
|
|
|
|
|
|
class bcolors:
|
2014-03-03 13:43:43 +01:00
|
|
|
DEBUG = '\033[94m'
|
|
|
|
INFO = '\033[95m'
|
2014-03-03 13:20:16 +01:00
|
|
|
SUCCESS = '\033[92m'
|
2014-03-03 12:10:06 +01:00
|
|
|
WARNING = '\033[93m'
|
|
|
|
FAIL = '\033[91m'
|
|
|
|
ENDC = '\033[0m'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|