forked from simons-public/protonfixes
-
Notifications
You must be signed in to change notification settings - Fork 74
/
logger.py
executable file
·69 lines (51 loc) · 1.59 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
""" Simple logging to stdout the same way Proton does
"""
import io
import os
import sys
class Log():
"""Log to stderr for steam dumps
"""
def __init__(self):
self.pfx = 'ProtonFixes[' + str(os.getpid()) + '] '
self.colors = {
'RESET': '\u001b[0m',
'INFO': '\u001b[34m',
'WARN': '\u001b[33m',
'CRIT': '\u001b[31m',
'DEBUG': '\u001b[35m'
}
def __call__(self, msg):
""" Allows the Log instance to be called directly
"""
self.log(msg)
def log(self, msg='', level='INFO'):
""" Prints the log message to stdout the same way as Proton
"""
pfx = self.pfx + level + ': '
color = self.colors[level]
reset = self.colors['RESET']
logtext = pfx + str(msg) + os.linesep
fulltext = color + pfx + str(msg) + reset + os.linesep
sys.stderr.write(fulltext)
sys.stderr.flush()
with io.open('/tmp/test', 'a', 1, encoding='utf-8') as testfile:
testfile.write(logtext)
def info(self, msg):
""" Wrapper for printing info messages
"""
self.log(msg, 'INFO')
def warn(self, msg):
""" Wrapper for printing warning messages
"""
self.log(msg, 'WARN')
def crit(self, msg):
""" Wrapper for printing critical messages
"""
self.log(msg, 'CRIT')
def debug(self, msg):
""" Wrapper for printing debug messages
"""
if 'DEBUG' in os.environ:
self.log(msg, 'DEBUG')
log = Log() #pylint: disable=C0103