-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdogcamlogger.py
78 lines (62 loc) · 1.77 KB
/
dogcamlogger.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
70
71
72
73
74
75
76
77
from enum import IntEnum, auto
from colorama import Fore, Style, init
import time
import datetime
__all__ = ["DCLogLevel", "DogCamLogger"]
class DCLogLevel(IntEnum):
Debug=auto()
Verbose=auto()
Log=auto()
Warn=auto()
Error=auto()
Notice=auto()
Silence=auto()
def __lt__(self, other):
if self.__class__ is other.__class__:
return self.value < other.value
return NotImplemented
@staticmethod
def GetLevel(ForStr: str):
try:
return DCLogLevel[ForStr]
except KeyError:
return DCLogLevel.Log
def ToString(self):
return self.name
CurrentLoggingLevel = DCLogLevel.Log
class DogCamLogger():
@staticmethod
def Start():
init()
@staticmethod
def GetTimestamp():
return time.time()
@staticmethod
def PrintDate():
NowTime = str(datetime.datetime.now())
return f"[{NowTime}] "
@staticmethod
def SetLogLevel(NewLevel:str):
global CurrentLoggingLevel
CurrentLoggingLevel = DCLogLevel.GetLevel(NewLevel.title())
@staticmethod
def Log(Input:str, LogLevel:DCLogLevel=DCLogLevel.Log, MakeBold:bool=False, MakeDim:bool=False):
if LogLevel < CurrentLoggingLevel:
return
# Set up color logging
ColorStr = ""
if LogLevel == DCLogLevel.Error:
ColorStr = Fore.RED + Style.BRIGHT
elif LogLevel == DCLogLevel.Warn:
ColorStr = Fore.YELLOW + Style.BRIGHT
elif LogLevel == DCLogLevel.Verbose:
ColorStr = Style.DIM
elif LogLevel == DCLogLevel.Debug:
ColorStr = Style.BRIGHT + Fore.BLACK
elif LogLevel == DCLogLevel.Notice:
ColorStr = Fore.GREEN + Style.BRIGHT
if MakeBold is True:
ColorStr += Style.BRIGHT
elif MakeDim is True:
ColorStr += Style.DIM
print(DogCamLogger.PrintDate() + f"DogCamAI:{ColorStr} {Input}" + Style.RESET_ALL)