loguru日志库
Python - loguru日志库,高效输出控制台日志和日志记录
pip install loguru from loguru import logger
logger.info("中文loguru")
logger.debug("中文loguru")
logger.error("中文loguru")
logger.warning("中文loguru")Last updated
pip install loguru from loguru import logger
logger.info("中文loguru")
logger.debug("中文loguru")
logger.error("中文loguru")
logger.warning("中文loguru")Last updated
# coding:utf-8
from loguru import logger
logger.add("interface_log_{time}.log", rotation="500MB", encoding="utf-8", enqueue=True, compression="zip", retention="10 days")
logger.info("中文test")
logger.debug("中文test")
logger.error("中文test")
logger.warning("中文test")logger.info('If you are using Python {}, prefer {feature} of course!', 3.6, feature='f-strings')
n1 = "cool"
n2 = [1, 2, 3]
logger.info(f'If you are using Python {n1}, prefer {n2} of course!')
运行结果
2020-03-07 16:19:25.363 | INFO | __main__:<module>:43 - If you are using Python 3.6, prefer f-strings of course!
2020-03-07 16:19:25.364 | INFO | __main__:<module>:46 - If you are using Python cool, prefer [1, 2, 3] of course!import time
from loguru import logger
from pathlib import Path
project_path = Path.cwd().parent
log_path = Path(project_path, "log")
t = time.strftime("%Y_%m_%d")
class Loggings:
__instance = None
logger.add(f"{log_path}/interface_log_{t}.log", rotation="500MB", encoding="utf-8", enqueue=True,
retention="10 days")
def __new__(cls, *args, **kwargs):
if not cls.__instance:
cls.__instance = super(Loggings, cls).__new__(cls, *args, **kwargs)
return cls.__instance
def info(self, msg):
return logger.info(msg)
def debug(self, msg):
return logger.debug(msg)
def warning(self, msg):
return logger.warning(msg)
def error(self, msg):
return logger.error(msg)
loggings = Loggings()
if __name__ == '__main__':
loggings.info("中文test")
loggings.debug("中文test")
loggings.warning("中文test")
loggings.error("中文test")
logger.info('If you are using Python {}, prefer {feature} of course!', 3.6, feature='f-strings')
n1 = "cool"
n2 = [1, 2, 3]
logger.info(f'If you are using Python {n1}, prefer {n2} of course!')