forked from Hackerbone/HackerLLMBench
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.py
More file actions
48 lines (39 loc) · 1.19 KB
/
logger.py
File metadata and controls
48 lines (39 loc) · 1.19 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
import logging
import colorlog
class Logger:
@staticmethod
def setup_logging(log_file=None):
log_colors = {
"DEBUG": "white",
"INFO": "green",
"WARNING": "yellow",
"ERROR": "red",
"CRITICAL": "bold_red",
}
formatter = colorlog.ColoredFormatter(
"%(log_color)s%(asctime)s [%(levelname)s] %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
log_colors=log_colors,
)
handlers = [logging.StreamHandler()]
if log_file:
handlers.append(logging.FileHandler(log_file))
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s [%(levelname)s] %(message)s",
handlers=handlers,
)
for handler in handlers:
handler.setFormatter(formatter)
@staticmethod
def info(*args):
logging.info(" ".join(map(str, args)))
@staticmethod
def error(*args):
logging.error(" ".join(map(str, args)))
@staticmethod
def debug(*args):
logging.debug(" ".join(map(str, args)))
@staticmethod
def warning(*args):
logging.warning(" ".join(map(str, args)))