-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathlog.py
More file actions
74 lines (59 loc) · 1.77 KB
/
log.py
File metadata and controls
74 lines (59 loc) · 1.77 KB
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
try:
import sublime
except ImportError:
from test.stubs import sublime
class Log:
"""
Logging facilities
"""
verbosity = None
VERB_NONE = 0
VERB_ERROR = 1
VERB_WARNING = 2
VERB_NORMAL = 3
VERB_DEBUG = 4
@classmethod
def reset(cls):
Log.verbosity = None
@classmethod
def error(cls,*msg):
Log._record(Log.VERB_ERROR, *msg)
@classmethod
def warning(cls,*msg):
Log._record(Log.VERB_WARNING, *msg)
@classmethod
def normal(cls,*msg):
Log._record(Log.VERB_NORMAL, *msg)
@classmethod
def debug(cls,*msg):
Log._record(Log.VERB_DEBUG, *msg)
@classmethod
def _record(cls, verb, *msg):
if not Log.verbosity:
Log._set_verbosity("none")
if verb <= Log.verbosity:
for line in ''.join(map(lambda x: str(x), msg)).split('\n'):
print('[SublimeStackIDE]['+cls._show_verbosity(verb)+']:',*msg)
if verb == Log.VERB_ERROR:
sublime.status_message('There were errors, check the console log')
elif verb == Log.VERB_WARNING:
sublime.status_message('There were warnings, check the console log')
@classmethod
def _set_verbosity(cls, input):
verb = input.lower()
if verb == "none":
Log.verbosity = Log.VERB_NONE
elif verb == "error":
Log.verbosity = Log.VERB_ERROR
elif verb == "warning":
Log.verbosity = Log.VERB_WARNING
elif verb == "normal":
Log.verbosity = Log.VERB_NORMAL
elif verb == "debug":
Log.verbosity = Log.VERB_DEBUG
else:
Log.verbosity = Log.VERB_WARNING
Log.warning("Invalid verbosity: '" + str(verb) + "'")
@classmethod
def _show_verbosity(cls,verb):
return ["?!","ERROR","WARN","NORM","DEBUG"][verb]