编程语言
首页 > 编程语言> > python loging 文件是空的问题

python loging 文件是空的问题

作者:互联网

不知道怎么回事,一个日志本地Macbook没问题,线上centos就输出了一个空文件:

原来代码

logHandler = TimedRotatingFileHandler(log_file, when='midnight', interval=1)
logHandler.setLevel(level=logging.INFO)
logging.basicConfig(level=logging.INFO,
                    format='%(asctime)s %(pathname)s %(filename)s %(funcName)s %(lineno)d %(levelname)s - %(message)s',
                    handlers=[logHandler])
print("__name__ is " + str(__name__))
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

这里用了basicConfig,结果logging file是个空文件

改成下面,去掉basicConfig就好了,原因未知

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
log_format = logging.Formatter('%(asctime)s %(pathname)s %(filename)s %(funcName)s %(lineno)d %(levelname)s - %(message)s')
logHandler = TimedRotatingFileHandler(log_file, when='midnight', interval=1)
logHandler.setLevel(level=logging.INFO)
logHandler.setFormatter(log_format)
logger.addHandler(logHandler)

 

标签:__,文件,logging,log,python,INFO,logHandler,logger,loging
来源: https://www.cnblogs.com/zjhgx/p/16294263.html