How to save and append (no overwiting after every bootup) the error log file for my Python code (added in rc.local service to run on reboot)?

I have added a python code in rc.local service to run on every bootup on my TX2. The code might throw errors and I would like to log them. Currently, I am doing this in my rc.local file:

/home/jetson/ > /usr/tmp/debug.log 2>&1 &
exit 0

In the above case, the log file is being generated, however, it is also getting overwritten on every boot up. I do not want the error log file to be overwritten for my application.

I have also tried:

/home/jetson/ >> /usr/tmp/debug.log 2>&1 &
exit 0

(In both cases, the last append sign I am using so that the booting doesn’t stop on the middle).

If it is not possible to have errors appended in the same file, I could also try any other method. I just want the error log file to have information about all session errors instead of the last/latest one.


Probably the best way is to use logrotate. This is why you get logs with a number, e.g., if you have kern.log, then a previous boot is shown in kern.log.1. Some logs will also show as the original log name plus older ones as “name.log.old”. See “man logrotate”.

Not sure, but I don’t think logrotate has changed much from Ubuntu 16.04 to 18.04, nor is it much different across other distributions (most information you find on the internet will work). A couple of URLs you might be interested in: