You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.6 KiB

5 months ago
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2025/4/12 14:51
# @Author : old-tom
# @File : log_conf
# @Project : sttFunctionCallBackend
# @Desc :
import sys
import os
from loguru import logger
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# 日志输出路径
LOG_PATH = os.path.join(BASE_DIR, r'logout/logout.log')
class Logger(object):
def __init__(self):
self.logger = logger
self.logger.remove()
self.logger.add(sys.stdout,
format="<green>{time:YYYY-MM-DD HH:mm:ss}</green> | " # 颜色>时间
"{process.name} | " # 进程名
"{thread.name} | " # 进程名
"<cyan>{module}</cyan>.<cyan>{function}</cyan>" # 模块名.方法名
":<cyan>{line}</cyan> | " # 行号
"<level>{level}</level>: " # 等级
"<level>{message}</level>", # 日志内容
)
# 输出到文件的格式,注释下面的add',则关闭日志写入
self.logger.add(LOG_PATH, level='DEBUG',
format='{time:YYYY-MM-DD HH:mm:ss} - ' # 时间
"{process.name} | " # 进程名
"{thread.name} | " # 进程名
'{module}.{function}:{line} - {level} -{message}', # 模块名.方法名:行号
rotation="10 MB")
def get_logger(self):
return self.logger
log = Logger().get_logger()