python-日志模块

如何让不同的错误往不同的日志文件写入?

# 创建一个操作日志的对象logger(依頼 FileHandler)
import logging
file_handler=logging.FileHandler("l1","a","utf-8")
file_handler.setFormatter(logging.Formatter(fmt="%(asctime)s - %(name)s - %(levelname)s - %(module)s: %(message)s"))

logger1 = logging.Logger("s1", level=logging.ERROR)
logger1.addHandler(file_handler)
logger1.error('123123123')

file_handler2=logging.FileHandler("l2","a","utf-8")
file_handler2.setFormatter(logging.Formatter(fmt="%(asctime)s - %(name)s - %(levelname)s - %(module)s: %(message)s"))

logger2=logging.Logger('s2', level=logging.ERROR)
logger2.addHandler(file_handler2)
logger2.error('666')

你可能感兴趣的:(Python,服务器,python)