forked from K0lb3/UnityPy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogger.py
More file actions
55 lines (40 loc) · 1.06 KB
/
Copy pathLogger.py
File metadata and controls
55 lines (40 loc) · 1.06 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
import time
from enum import Enum
from colorama import init
from termcolor import colored
init()
COLOR = {
'Verbose': 'white',
'Debug': 'green',
'Info': 'yellow',
'Warning': 'magenta',
'Error': 'red'
}
class LoggerEvent(Enum):
Verbose = 0,
Debug = 1,
Info = 2,
Warning = 3,
Error = 4
def print(self, string):
print(colored(f"{self.name}: {string}", COLOR[self.name]))
class Logger:
log: list
print: bool
def __init__(self, print: bool = False):
self.print = print
self.log = []
def _log(self, event: LoggerEvent, message: str):
if self.print:
event.print(message)
self.log.append((event, message))
def verbose(self, message: str):
self._log(LoggerEvent.Verbose, message)
def debug(self, message: str):
self._log(LoggerEvent.Debug, f"{time.thread_time_ns()} - {message}")
def info(self, message: str):
self._log(LoggerEvent.Info, message)
def warning(self, message: str):
self._log(LoggerEvent.Warning, message)
def error(self, message: str, error: Exception):
self._log(LoggerEvent.Error, '\n'.join([message, str(error)]))