Reputation: 87
I want to set a time-stamp on log.txt
file for every output line. It's doing what I want it to do in terminal output. how would I go about to set the time-stamp in log.txt
file?
Command:
python ig.py |& tee -a log.txt | ts '[%Y-%m-%d %H:%M:%S]'
Terminal Output:
[2017-04-19 08:38:48] DEBUG:__main__:Liking 1494171280764517709
[2017-04-19 08:38:49] DEBUG:__main__:Sleeping for 33.919725732684476
log.txt Output:
DEBUG:__main__:Liking 1494171280764517709
DEBUG:__main__:Sleeping for 33.919725732684476
Upvotes: 1
Views: 830
Reputation: 57490
Move the ts
before the tee
so that the timestamp is added to the output before it's written to the file:
python ig.py |& ts '[%Y-%m-%d %H:%M:%S]' | tee -a log.txt
Upvotes: 1