This repository was archived by the owner on Mar 31, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathlog.py
More file actions
58 lines (40 loc) · 1.16 KB
/
log.py
File metadata and controls
58 lines (40 loc) · 1.16 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
import sys
class Color(object):
DEBUG = '\033[35m'
INFO = '\033[32m'
WARNING = '\033[31m'
ERROR = '\033[31m'
ENDC = '\033[0m'
@classmethod
def _deco(cls, msg, color):
return '%s%s%s' % (color, msg, cls.ENDC)
@classmethod
def debug(cls, msg):
return cls._deco(msg, cls.DEBUG)
@classmethod
def info(cls, msg):
return cls._deco(msg, cls.INFO)
@classmethod
def warning(cls, msg):
return cls._deco(msg, cls.WARNING)
@classmethod
def error(cls, msg):
return cls._deco(msg, cls.ERROR)
class Logger(object):
def debug(self, msg):
self._stdout(Color.debug("DEBUG: %s\n" % msg))
def log(self, msg):
self._stdout("%s\n" % (msg))
def info(self, msg):
self._stdout(Color.info('%s\n' % msg))
def warning(self, msg):
self._stderr(Color.warning("WARNING: %s\n" % msg))
def error(self, msg):
self._stderr(Color.error("ERROR: %s\n" % msg))
def _stdout(self, msg):
sys.stdout.write(msg)
sys.stdout.flush()
def _stderr(self, msg):
sys.stderr.write(msg)
sys.stderr.flush()
logger = Logger()