2023-02-06 17:46:47 +00:00
|
|
|
import Scrap
|
2023-02-07 08:38:24 +00:00
|
|
|
import string
|
2023-02-06 17:46:47 +00:00
|
|
|
|
|
|
|
class Logger:
|
|
|
|
|
|
|
|
def __init__(self, name):
|
2023-02-07 08:38:24 +00:00
|
|
|
self.level = ""
|
|
|
|
self.name = name
|
2023-02-06 17:46:47 +00:00
|
|
|
|
|
|
|
def __repr__(self):
|
2023-02-07 08:38:24 +00:00
|
|
|
return "<Logger: " + self.name + ">"
|
2023-02-06 17:46:47 +00:00
|
|
|
|
2023-02-07 08:38:24 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.__repr__()
|
2023-02-06 17:46:47 +00:00
|
|
|
|
2023-02-07 08:38:24 +00:00
|
|
|
def __call__(self, *args):
|
|
|
|
if string.find(self.level, "__") == 0:
|
|
|
|
return
|
2023-02-06 17:46:47 +00:00
|
|
|
|
2023-02-07 08:38:24 +00:00
|
|
|
args = list(args)
|
2023-02-06 17:46:47 +00:00
|
|
|
|
2023-02-07 08:38:24 +00:00
|
|
|
for i in range(len(args)):
|
|
|
|
args[i] = str(args[i])
|
|
|
|
if args[i] == None:
|
|
|
|
args[i] = ""
|
2023-02-06 17:46:47 +00:00
|
|
|
|
2023-02-07 08:38:24 +00:00
|
|
|
args = ["[" + str(self.name) + "|" + string.upper(self.level) + "]"] + args
|
|
|
|
msg = string.join(args, " ")
|
|
|
|
Scrap.Print(msg + "\n")
|
2023-02-06 17:46:47 +00:00
|
|
|
|
|
|
|
def __getattr__(self, level):
|
2023-02-07 08:38:24 +00:00
|
|
|
self.level = level
|
2023-02-06 17:46:47 +00:00
|
|
|
return self
|
2023-02-07 08:38:24 +00:00
|
|
|
|
|
|
|
def __nonzero__(self):
|
|
|
|
return True
|
|
|
|
|
|
|
|
def __bool__(self):
|
|
|
|
return True
|