欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

python日志模块为什么打印到界面_如何将外部模块的日志消息打印到主Python模块的终端窗口?...

发布时间:2025/4/16 30 豆豆
生活随笔 收集整理的这篇文章主要介绍了 python日志模块为什么打印到界面_如何将外部模块的日志消息打印到主Python模块的终端窗口?... 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

我正在写一个Python命令行程序。在

有一个主Python脚本文件,用作入口点。当用户运行这个脚本时,它将执行一些外部Python脚本文件。外部Python脚本文件也可以执行其他外部Python脚本文件。外部文件的数量是可变的。在

Python脚本将使用以下方式执行外部Python脚本:p = subprocess.Popen(args)

or

p = subprocess.call(args)

当我在终端窗口中运行主Python脚本时,它将在运行时在屏幕上打印实时日志消息。现在,我希望从主Python脚本调用的所有外部Python脚本获取所有日志消息,并将其打印到同一个终端窗口(我用来运行主脚本的终端窗口)。在

例如,以下是脚本执行的顺序:

^{pr2}$

当我在终端窗口中运行主脚本时,是否可以像下面这样在终端窗口上获得实时日志消息?在[time-hh-mm-ss][log message from main script]Script is running..

[time-hh-mm-ss][log message from main script]Calling script layer-1-script-1..

[time-hh-mm-ss][log message from layer-1-script-1]Script is running..

[time-hh-mm-ss][log message from layer-1-script-1]Calling script layer-2-script-1..

[time-hh-mm-ss][log message from layer-2-script-1]Script is running..

[time-hh-mm-ss][log message from layer-2-script-1]Calling script layer-2-script-2..

[time-hh-mm-ss][log message from layer-2-script-2]Script is running..

[time-hh-mm-ss][log message from layer-2-script-2]Calling script layer-1-script-2..

[time-hh-mm-ss][log message from layer-1-script-2]Script is running..

[time-hh-mm-ss][log message from layer-1-script-2]Calling script layer-1-script-3..

[time-hh-mm-ss][log message from layer-2-script-3]Script is running..

[time-hh-mm-ss][log message from main script]Back to main script. Script is running..

有没有可能我可以在终端窗口中得到一个real time log messages类似的内容?在

总结

以上是生活随笔为你收集整理的python日志模块为什么打印到界面_如何将外部模块的日志消息打印到主Python模块的终端窗口?...的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。