import logging,time,os,sys
'''
使用方法:在project主目录下新建lib目录,将logger_fengzhuang.py文件复制进去
调用方式:
logger = Logger(file_or_terminal="file", level="DEBEG").getLogger()
# logger = Logger(file_or_terminal="terminal").getLogger()
# logger = Logger(file_or_terminal="all").getLogger()
logger.debug("debug")
logger.info("info")
logger.error("info")
# file_or_terminal == terminal: 只打印到命令行
# file_or_terminal == file: 只打印到日志文件
# file_or_terminal == all: 同时打印到日志文件和命令行
# level = CRITICAL','ERROR','WARNING','INFO','DEBUG
'''
class Logger():
def __init__(self, file_or_terminal="file", level="ERROR"):
self.logger = logging.getLogger()
self.logger.setLevel(level)
info = '''
file_or_terminal == terminal: 只打印到命令行
file_or_terminal == file: 只打印到日志文件
file_or_terminal == all: 同时打印到日志文件和命令行
level = CRITICAL','ERROR','WARNING','INFO','DEBUG
'''
proDir
python日志模块--封装
最新推荐文章于 2024-07-01 13:34:28 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)