forked from BinNong/meet-libai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.py
58 lines (49 loc) · 1.46 KB
/
logger.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
# -*- coding: utf-8 -*-
# @Time : 2024/1/31 17:57
# @Author : nongbin
# @FileName: logger.py
# @Software: PyCharm
# @Affiliation: tfswufe.edu.cn
import os.path
from typing import Optional
from loguru import logger
from env import get_app_root
if not os.path.exists(os.path.join(get_app_root(), "logs")):
os.makedirs(os.path.join(get_app_root(), "logs"))
class Logger:
"""
定义一个全局日志工具类,设置好路径、rotation等信息
"""
def __init__(self, name: Optional[str] = None):
"""
初始化日志工具类
"""
# 设置日志文件路径
self.logger = logger
self.logger.add(os.path.join(get_app_root(), "logs", f"{name if name else 'file_{time}'}.log")
, rotation='10 MB'
, retention='30 days')
def info(self, message):
"""
输出INFO级别的日志
:param message: 日志信息
"""
self.logger.info(message)
def debug(self, message):
"""
输出DEBUG级别的日志
:param message: 日志信息
"""
self.logger.debug(message)
def warning(self, message):
"""
输出WARNING级别的日志
:param message: 日志信息
"""
self.logger.warning(message)
def error(self, message):
"""
输出ERROR级别的日志
:param message: 日志信息
"""
self.logger.error(message)