'pyinstaller应用程序中的日志记录工作错误:调用模块和函数设置为'logging'和'debug''

2024-09-29 06:26:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个python应用程序,它使用模块“logging”并用pysintaller打包。在

我正在使用以下格式字符串:

%(asctime)s %(levelname)s [%(threadName)s:%(module)s.%(funcName)s()] %(message)s

如果我以python脚本运行应用程序,它可以正常工作,“(module)s.%(funcName)s”将替换为调用模块和函数的实际值:

^{pr2}$

但是,如果我用pyinstaller打包我的应用程序,它现在会替代'日志记录.debug'对于“%(module)s.%(funcName)s':

2014-06-19 19:04:05,577 DEBUG [MainThread:logging.debug()] Executing `echo hello` on server centos6root
2014-06-19 19:04:05,577 DEBUG [MainThread:logging.debug()] Trying to connect to server centos6root
2014-06-19 19:04:06,293 DEBUG [MainThread:logging.debug()] Established connection with root@192.168.122.57:22
2014-06-19 19:04:06,705 DEBUG [MainThread:logging.debug()] exitstatus = 0
2014-06-19 19:04:06,707 DEBUG [MainThread:logging.debug()] Closed connection to server centos6root
2014-06-19 19:04:06,707 DEBUG [MainThread:logging.debug()] Application finished

原因是什么?如何纠正这种行为?在


Tags: 模块to字符串debug应用程序serverlogging格式
1条回答
网友
1楼 · 发布于 2024-09-29 06:26:16

我使用的是直接调用logging.info()logging.debug()

通过对每个模块使用单独的记录器解决了这个问题

import logging
logger = logging.getLogger(__name__)

并调用logger.info()logger.debug()

相关问题 更多 >