标签:info mes mha log imp war ror time mode
import logging
logging.basicConfig(level=logging.DEBUG, #对日志基础设定
filename = "logger.log",
filemode=‘w‘,
format="%(filename)s %(lineno)d %(asctime)s %(message)s" #显示文件名 显示行号 显示时间 显示信息
)
logging.debug(‘debug message‘)
logging.info(‘info message‘)
logging.warning(‘warning message‘)
logging.error(‘error message‘)
logging.critical(‘critical message‘)
#--------------------------------------------logger----------------------------------------------------------------------
def logger():
logger = logging.getLogger()
fh = logging.FileHandler("test_log")
ch = logging.StreamHandler()
fm = logging.Formatter("%(filename)s %(lineno)d %(asctime)s %(message)s")
fh.setFormatter(fm)
ch.setFormatter(fm)
logger.addHandler(fh)
logger.addHandler(ch)
logger.setLevel("DEBUG")
return logger
logger = logger()
logger.debug("debug")
logger.info("info")
logger.warning("warning")
logger.error("error")
logger.critical("critical")
#------------------------------------------------------------------------------------------------------------------------
logger = logging.getLogger() #父亲 root
logger1 = logging.getLogger("my logger") #儿子
logger1.setLevel("DEBUG")
fh = logging.FileHandler("test_log")
ch = logging.StreamHandler()
logger.addHandler(fh)
logger.addHandler(ch)
logger1.addHandler(fh)
logger1.addHandler(ch)
logger.debug("logger debug")
logger.info("logger info")
logger.warning("logger warning")
logger.error("logger error")
logger.critical("logger critical")
logger1.debug("logger1 debug")
logger1.info("logger1 info")
logger1.warning("logger1 warning")
logger1.error("logger1 error")
logger1.critical("logger1 critical")
标签:info mes mha log imp war ror time mode
原文地址:https://www.cnblogs.com/zhangsenzhen/p/9419937.html