python日志模块为什么打印到界面_如何将外部模块的日志消息打印到主Python模块的终端窗口?...
我正在寫一個(gè)Python命令行程序。在
有一個(gè)主Python腳本文件,用作入口點(diǎn)。當(dāng)用戶運(yùn)行這個(gè)腳本時(shí),它將執(zhí)行一些外部Python腳本文件。外部Python腳本文件也可以執(zhí)行其他外部Python腳本文件。外部文件的數(shù)量是可變的。在
Python腳本將使用以下方式執(zhí)行外部Python腳本:p = subprocess.Popen(args)
or
p = subprocess.call(args)
當(dāng)我在終端窗口中運(yùn)行主Python腳本時(shí),它將在運(yùn)行時(shí)在屏幕上打印實(shí)時(shí)日志消息。現(xiàn)在,我希望從主Python腳本調(diào)用的所有外部Python腳本獲取所有日志消息,并將其打印到同一個(gè)終端窗口(我用來(lái)運(yùn)行主腳本的終端窗口)。在
例如,以下是腳本執(zhí)行的順序:
^{pr2}$
當(dāng)我在終端窗口中運(yùn)行主腳本時(shí),是否可以像下面這樣在終端窗口上獲得實(shí)時(shí)日志消息?在[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..
有沒(méi)有可能我可以在終端窗口中得到一個(gè)real time log messages類似的內(nèi)容?在
總結(jié)
以上是生活随笔為你收集整理的python日志模块为什么打印到界面_如何将外部模块的日志消息打印到主Python模块的终端窗口?...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: dp线长什么样子_怎么样选择好的DP线?
- 下一篇: python怎么字体加阴影_如何添加阴影