riku
2024-01-10 a9e8e27e0503552b7b2a99c821da732175d4f071
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
from utils.date_utils import DateUtils
from db.repository.request_task_rep import RequestTaskRepository
 
 
def get_prefix(prefix=0):
    if prefix == 0:
        return "|- "
    elif prefix == 1:
        return "| "
    elif prefix == 2:
        return ""
 
 
rep_request_task = RequestTaskRepository()
 
 
class LogUtils:
 
    task_id = None
 
    @staticmethod
    def log(message):
        str = '[' + DateUtils.now_time()+']: ' + message
        print(str)
 
    @staticmethod
    def debug(message):
        str = '[DEBUG] ' + '[' + DateUtils.now_time()+']: ' + message
        print(str)
 
    # 一切按照预期进行
 
    @staticmethod
    def info(message, prefix=0):
        str = '[INFO ] ' + '[' + DateUtils.now_time()+']: ' + get_prefix(prefix) + message
        # logging.info(str)
        print(str)
 
    # 有潜在问题
    @staticmethod
    def warn(message, e='', prefix=0):
        str = '[WARN ] ' + '[' + DateUtils.now_time()+']: ' + get_prefix(prefix) + message
        # logging.warning(str)
        print(str, e)
 
    # 严重的问题,软件不能运行
    @staticmethod
    def error(message, e='', prefix=0):
        s = '[ERROR] ' + '[' + DateUtils.now_time()+']: ' + get_prefix(prefix) + message
        # logging.error(str)
        print(s, e)
        rep_request_task.insert_log(LogUtils.task_id, "error", s + str(e))