python - pyinstaller 应用程序的日志记录工作错误 : calling module and function are set to 'logging' and 'debug'

标签 python logging pyinstaller

我有一个使用模块“logging”的Python应用程序,我用pysintaller将其打包。

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

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

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

2014-06-19 18:46:10,373 DEBUG [MainThread:subcommands.exec_cmd()] Executing `service iptables stop` on server centos6root
2014-06-19 18:46:10,373 DEBUG [MainThread:ssh._connect()] Trying to connect to server centos6root
2014-06-19 18:46:10,945 DEBUG [MainThread:ssh._connect()] Established connection with root@192.168.122.57:22
2014-06-19 18:46:11,533 DEBUG [MainThread:subcommands.exec_cmd()] exitstatus = 0
2014-06-19 18:46:11,648 DEBUG [MainThread:ssh.cleanup()] Closed connection to server centos6root
2014-06-19 18:46:11,649 DEBUG [MainThread:hwswa2.main()] Application finished

但是,如果我使用 pyinstaller 打包应用程序,它现在会用“logging.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

原因是什么以及如何解决此问题?

最佳答案

我使用直接调用 logging.info()logging.debug() 等。

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

import logging
logger = logging.getLogger(__name__)

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

关于python - pyinstaller 应用程序的日志记录工作错误 : calling module and function are set to 'logging' and 'debug' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24306246/

相关文章:

python - 计算给定(x,y)坐标的多边形面积

python - 比较两个列表中元素的有效方法

java - 如何在 log4j 中记录第二个参数

python - 如何使用 celery 任务创建单个文件可执行文件

python-3.x - Pyinstaller .exe 找不到 _tiffile 模块 - 加载一些压缩图像会很慢

python - tensorflow2.0还有参数 'trainable'吗?

python - 如何将地址模型链接到 View

java - 如何扩展 Flogger Fluent API 以获取特定于域的属性?

c# - 为什么我的 log4net appender 没有缓冲?

pyinstaller - 当我运行使用 pyinstaller 部署的程序时出现“没有名为 atexit 的模块”