This repository has been archived by the owner on Aug 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger.py
56 lines (44 loc) · 1.56 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
# Copyright (c) 2020 s-blu
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import json
from writerey_config import debugMode
class bcolors:
DEBUG = '\033[30m'
OK = '\033[92m'
WARNING = '\033[93m'
ERROR = '\033[91m'
END = '\033[0m'
class Logger:
def __init__(self, pre='', silenced=False):
self.prefix = pre
self.silenced = silenced
def logDebug(self, *msg):
if (debugMode and not self.silenced):
print(f'{bcolors.DEBUG}[debug]{bcolors.END}',
'[' + self.prefix + ']', self.parseToString(*msg))
def logInfo(self, *msg):
print('[Info] [' + self.prefix + ']', self.parseToString(*msg))
def logWarn(self, *msg):
print(f'{bcolors.WARNING}-[WARN]{bcolors.END}',
'[' + self.prefix + ']', self.parseToString(*msg))
def logError(self, *msg):
print(f'{bcolors.ERROR}--[[ERROR]]{bcolors.END}',
'[' + self.prefix + ']', self.parseToString(*msg))
def parseToString(self, *msg):
concatted = ''
try:
for m in msg:
try:
concatted += ' ' + m
except:
try:
m = json.dumps(m)
concatted += ' ' + m
except:
pass
except:
concatted = 'ERROR ON PARSING LOG STRING'
return concatted