modifié: m/log.py
modifié: superTornado.py
This commit is contained in:
parent
a8a2ce9b7b
commit
3d6ab87ec4
33
m/log.py
33
m/log.py
@ -1,8 +1,33 @@
|
|||||||
|
import logging
|
||||||
|
from logging.handlers import RotatingFileHandler
|
||||||
import time
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
class Log(object):
|
class Log(object):
|
||||||
def enregDansLog(self,pLog,pMsg,pIP):
|
def __init__(self) :
|
||||||
with open("m/fichier/log", "a") as dest :
|
# création de l'objet logger qui va nous servir à écrire dans les logs
|
||||||
d = datetime.now().strftime("%c")
|
self.logger = logging.getLogger()
|
||||||
dest.write("%s,%s,%s,%s\n" % (d,pLog,pMsg,pIP))
|
# on met le niveau du logger à DEBUG, comme ça il écrit tout
|
||||||
|
self.logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
# création d'un formateur qui va ajouter le temps, le niveau
|
||||||
|
# de chaque message quand on écrira un message dans le log
|
||||||
|
formatter = logging.Formatter('%(asctime)s :: %(levelname)s :: %(message)s')
|
||||||
|
# création d'un handler qui va rediriger une écriture du log vers
|
||||||
|
# un fichier en mode 'append', avec 1 backup et une taille max de 1Mo
|
||||||
|
file_handler = RotatingFileHandler('m/fichier/log', 'a', 1000000, 1)
|
||||||
|
# on lui met le niveau sur DEBUG, on lui dit qu'il doit utiliser le formateur
|
||||||
|
# créé précédement et on ajoute ce handler au logger
|
||||||
|
file_handler.setLevel(logging.DEBUG)
|
||||||
|
file_handler.setFormatter(formatter)
|
||||||
|
self.logger.addHandler(file_handler)
|
||||||
|
|
||||||
|
# création d'un second handler qui va rediriger chaque écriture de log
|
||||||
|
# sur la console
|
||||||
|
self.steam_handler = logging.StreamHandler()
|
||||||
|
self.steam_handler.setLevel(logging.DEBUG)
|
||||||
|
logger.addHandler(steam_handler)
|
||||||
|
|
||||||
|
|
||||||
|
def printL(self,pMsg):
|
||||||
|
self.logger.info(pMsg)
|
||||||
|
@ -36,6 +36,7 @@ class BaseHandler(tornado.web.RequestHandler):
|
|||||||
|
|
||||||
class MainHandler(BaseHandler):
|
class MainHandler(BaseHandler):
|
||||||
def get(self):
|
def get(self):
|
||||||
|
print ("->")
|
||||||
self.render("v/index.html")
|
self.render("v/index.html")
|
||||||
|
|
||||||
def post(self):
|
def post(self):
|
||||||
@ -90,7 +91,7 @@ class WSocketHandler(BaseHandler,tornado.websocket.WebSocketHandler):
|
|||||||
print "->Websocket opened : " + self.request.remote_ip
|
print "->Websocket opened : " + self.request.remote_ip
|
||||||
iden = self.current_user
|
iden = self.current_user
|
||||||
if self.get_autorisation == "yes":
|
if self.get_autorisation == "yes":
|
||||||
ficLog.enregDansLog(iden,"Authorized user connection",self.request.remote_ip)
|
ficLog.printL(iden +" Authorized user connection " + self.request.remote_ip)
|
||||||
if confAveug == True:
|
if confAveug == True:
|
||||||
print '->Send audio alarm authorized user'
|
print '->Send audio alarm authorized user'
|
||||||
print 'maison.request("GET", "micom/say.php?source=toto&text=Connection%20a%20la%20camera%20autorisee")'
|
print 'maison.request("GET", "micom/say.php?source=toto&text=Connection%20a%20la%20camera%20autorisee")'
|
||||||
@ -99,7 +100,7 @@ class WSocketHandler(BaseHandler,tornado.websocket.WebSocketHandler):
|
|||||||
print 'maison.request("GET", "micom/lamp.php?room=salon1&order=1")'
|
print 'maison.request("GET", "micom/lamp.php?room=salon1&order=1")'
|
||||||
print "->Authorized user access : " + self.request.remote_ip
|
print "->Authorized user access : " + self.request.remote_ip
|
||||||
else :
|
else :
|
||||||
ficLog.enregDansLog(iden + " as IllegalUser","Unauthorized user connection",self.request.remote_ip)
|
ficLog.printL(iden + " as IllegalUser Unauthorized user connection" + self.request.remote_ip)
|
||||||
if confAveug == True:
|
if confAveug == True:
|
||||||
print '->Send audio alarm unauthorized user'
|
print '->Send audio alarm unauthorized user'
|
||||||
print 'maison.request("GET", "micom/say.php?source=toto&text=Connection%20a%20la%20camera%20non%20autorisee")'
|
print 'maison.request("GET", "micom/say.php?source=toto&text=Connection%20a%20la%20camera%20non%20autorisee")'
|
||||||
@ -117,9 +118,9 @@ class WSocketHandler(BaseHandler,tornado.websocket.WebSocketHandler):
|
|||||||
print "->Websocket closed : "+self.request.remote_ip
|
print "->Websocket closed : "+self.request.remote_ip
|
||||||
iden = self.current_user
|
iden = self.current_user
|
||||||
if self.get_autorisation == "yes":
|
if self.get_autorisation == "yes":
|
||||||
ficLog.enregDansLog(iden,"Authorized user deconnection",self.request.remote_ip)
|
ficLog.printL(iden +" Authorized user deconnection " + self.request.remote_ip)
|
||||||
else :
|
else :
|
||||||
ficLog.enregDansLog(iden + " as IllegalUser","Unauthorized user deconnection",self.request.remote_ip)
|
ficLog.printL(iden + " as IllegalUser Unauthorized user deconnection" + self.request.remote_ip)
|
||||||
|
|
||||||
if confAveug == True:
|
if confAveug == True:
|
||||||
print '->Send audio alarm deconnection user'
|
print '->Send audio alarm deconnection user'
|
||||||
|
Reference in New Issue
Block a user