forked from Max77T/plantmap-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.py
81 lines (69 loc) · 1.97 KB
/
logger.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# coding: utf8
import time
from PyQt4.QtCore import QObject
from PyQt4 import QtCore
import threading
lock = threading.Lock()
class Logger(QObject):
"""
This class Logger propose to log with 3 level for 3 output
Level : DEBUG | INFO | ERROR
The Logger used handlers. You can create handlers and added this with class Handlers
"""
DEBUG = "DEBUG"
INFO = "INFO"
ERROR = "ERROR"
outputList = []
instance = None
def __new__(cls):
with lock:
if cls.instance is None:
cls.instance = QObject.__new__(cls)
cls.instance.outputList = []
return cls.instance
def __init__(self):
with lock:
super(Logger, self).__init__()
def addOutput(self, outputBranch):
with lock:
self.outputList.append(outputBranch)
def removeOutput(self, outputBranch):
with lock:
for i, o in enumerate(self.outputList):
if o == outputBranch:
outputBranch.close()
del self.outputList[i]
break
"""
LEVEL
"""
def debug(self, mess):
"""
This method display a green message which is usefull to the developper
"""
try:
newMess = unicode(str(time.strftime("%Y-%m-%d %H:%M:%S")) + " ::DEBUG:: {m}".format(m=mess), "utf-8")
except UnicodeError:
newMess = mess.encode('utf-8')
for out in self.outputList:
out.emit(Logger.DEBUG, newMess)
def info(self, mess):
"""
This method display a blue message which indicate to the user the progress of the operation
"""
try:
newMess = unicode(str(time.strftime("%Y-%m-%d %H:%M:%S")) + " ::INFO:: {m}".format(m=mess), "utf-8")
except UnicodeError:
newMess = mess.encode('utf-8')
for out in self.outputList:
out.emit(Logger.INFO, newMess)
def error(self, mess):
"""
This method display a red message which show an Error during the process
"""
try:
newMess = unicode(str(time.strftime("%Y-%m-%d %H:%M:%S")) + " ::ERROR:: {m}".format(m=mess), "utf-8")
except UnicodeError:
newMess = mess.encode('utf-8')
for out in self.outputList:
out.emit(Logger.ERROR, newMess)