I am writing a Python command line program.
There is a main Python script file, acting as the entry point. When user run this script, it will execute a few external Python script files. The external Python script files may also execute other external Python script files. The number of external files is variable.
The Python script will execute external Python scripts using:
p = subprocess.Popen(args)
or
p = subprocess.call(args)
When I run the main Python script in a terminal window, it will print real time log messages on the screen when it is running. Now, I would like to get all log messages from all external Python scripts called by the main Python script and print it onto the same terminal window (the terminal window that I use to run the main script).
For example, below are the sequence of script execution:
1.Main-script
|
2.Layer-1-script-1
|
3.Layer-2-script-1
|
4.Layer-2-script-2
|
5.Layer-1-script-2
|
6.Layer-1-script-3
|
7.Main-script(continued)
When I run the main script in a terminal window, is it possible that I can get real time log messages on my terminal window like below?
[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..
Is it possible that I can get a real time log messages
like above in the terminal window?