Issue
I have a simple long running python script which logs using print("text to log")
. I want to run this as a background process but the output is only dumped into the specified log file when the process terminates. Is there a way to log in real time so that I can tail the logfile? I don't want to introduce unnecessary complexity in my python script; I'd rather allow the OS to handle the logging. Therefore I'm not keen in using a Logger
class for example.
I've tried the alternatives below to no avail:
nohup python start.py > test.log 2>&1 </dev/null &
python start.py >> test.log 2>&1 &
Thx
Solution
Try to run Python "unbuffered", i.e.
python -u start.py > test.log
Answered By - uselpa