2 added 48 characters in body
source | link

I personally believe that one the very first things that you have to do in a command-line script or application is setup a logging system. Just with a couple of re-usable lines, you can have logging on all your python applications and even use different debug levels :).

I wouldn't base logging in writing stdout to files with tee, just log to both stdout and your logging channel. I'm assuming that you can modify your python scripts, everything below applies to that situation. (scroll down for the "using tee answer" :).

In Python, you can use the Logging module (check the Logging HOWTO in the official Python documentation : https://docs.python.org/2/howto/logging.html) but unfortunately different processes cannot write to the same file (different theads of the same process can).

So, in this case you're describing, I think the base case will be log to syslog, either with the Logging library, or with the Syslog Library (https://docs.python.org/2/library/syslog.html).

You could log to syslog's local0.* facility on all the applications and let syslog (rsyslog in my case) to write to the file:

local0.*                /var/log/myapp.log

The best about this system is that you can even log to remote syslog servers on different machines, not only in the one executing the apps.

PS: Don't forget to set a /etc/logrotate.d/myapp policy to rotate your app log files!

The tee option

If you still need to use tee, did you try to use the -a flag for the 2nd and 3rd process? As stated in http://docstore.mik.ua/orelly/unix/upt/ch13_10.htm:

The tee ( 13.9 ) command writes its standard input to a file and writes the same text to its standard output. You might want to collect several commands' output and tee them all to the same file, one after another. The obvious way to do that is with the -a option

$ some-command | tee teefile

$ another-command | tee -a teefile

$ a-third-command | tee -a teefile

I personally believe that one the very first things that you have to do in a command-line script or application is setup a logging system. Just with a couple of re-usable lines, you can have logging on all your python applications and even use different debug levels :).

I wouldn't base logging in writing stdout to files with tee, just log to both stdout and your logging channel. I'm assuming that you can modify your python scripts, everything below applies to that situation.

In Python, you can use the Logging module (check the Logging HOWTO in the official Python documentation : https://docs.python.org/2/howto/logging.html) but unfortunately different processes cannot write to the same file (different theads of the same process can).

So, in this case you're describing, I think the base case will be log to syslog, either with the Logging library, or with the Syslog Library (https://docs.python.org/2/library/syslog.html).

You could log to syslog's local0.* facility on all the applications and let syslog (rsyslog in my case) to write to the file:

local0.*                /var/log/myapp.log

The best about this system is that you can even log to remote syslog servers on different machines, not only in the one executing the apps.

PS: Don't forget to set a /etc/logrotate.d/myapp policy to rotate your app log files!

The tee option

If you still need to use tee, did you try to use the -a flag for the 2nd and 3rd process? As stated in http://docstore.mik.ua/orelly/unix/upt/ch13_10.htm:

The tee ( 13.9 ) command writes its standard input to a file and writes the same text to its standard output. You might want to collect several commands' output and tee them all to the same file, one after another. The obvious way to do that is with the -a option

$ some-command | tee teefile

$ another-command | tee -a teefile

$ a-third-command | tee -a teefile

I personally believe that one the very first things that you have to do in a command-line script or application is setup a logging system. Just with a couple of re-usable lines, you can have logging on all your python applications and even use different debug levels :).

I wouldn't base logging in writing stdout to files with tee, just log to both stdout and your logging channel. I'm assuming that you can modify your python scripts, everything below applies to that situation. (scroll down for the "using tee answer" :).

In Python, you can use the Logging module (check the Logging HOWTO in the official Python documentation : https://docs.python.org/2/howto/logging.html) but unfortunately different processes cannot write to the same file (different theads of the same process can).

So, in this case you're describing, I think the base case will be log to syslog, either with the Logging library, or with the Syslog Library (https://docs.python.org/2/library/syslog.html).

You could log to syslog's local0.* facility on all the applications and let syslog (rsyslog in my case) to write to the file:

local0.*                /var/log/myapp.log

The best about this system is that you can even log to remote syslog servers on different machines, not only in the one executing the apps.

PS: Don't forget to set a /etc/logrotate.d/myapp policy to rotate your app log files!

The tee option

If you still need to use tee, did you try to use the -a flag for the 2nd and 3rd process? As stated in http://docstore.mik.ua/orelly/unix/upt/ch13_10.htm:

The tee ( 13.9 ) command writes its standard input to a file and writes the same text to its standard output. You might want to collect several commands' output and tee them all to the same file, one after another. The obvious way to do that is with the -a option

$ some-command | tee teefile

$ another-command | tee -a teefile

$ a-third-command | tee -a teefile

1
source | link

I personally believe that one the very first things that you have to do in a command-line script or application is setup a logging system. Just with a couple of re-usable lines, you can have logging on all your python applications and even use different debug levels :).

I wouldn't base logging in writing stdout to files with tee, just log to both stdout and your logging channel. I'm assuming that you can modify your python scripts, everything below applies to that situation.

In Python, you can use the Logging module (check the Logging HOWTO in the official Python documentation : https://docs.python.org/2/howto/logging.html) but unfortunately different processes cannot write to the same file (different theads of the same process can).

So, in this case you're describing, I think the base case will be log to syslog, either with the Logging library, or with the Syslog Library (https://docs.python.org/2/library/syslog.html).

You could log to syslog's local0.* facility on all the applications and let syslog (rsyslog in my case) to write to the file:

local0.*                /var/log/myapp.log

The best about this system is that you can even log to remote syslog servers on different machines, not only in the one executing the apps.

PS: Don't forget to set a /etc/logrotate.d/myapp policy to rotate your app log files!

The tee option

If you still need to use tee, did you try to use the -a flag for the 2nd and 3rd process? As stated in http://docstore.mik.ua/orelly/unix/upt/ch13_10.htm:

The tee ( 13.9 ) command writes its standard input to a file and writes the same text to its standard output. You might want to collect several commands' output and tee them all to the same file, one after another. The obvious way to do that is with the -a option

$ some-command | tee teefile

$ another-command | tee -a teefile

$ a-third-command | tee -a teefile