traccar / traccar

Traccar GPS Tracking System
https://www.traccar.org
Apache License 2.0
5.32k stars 2.6k forks source link

close and re-create/-open log file(s) on SIGNAL #4878

Open sock3t opened 2 years ago

sock3t commented 2 years ago

Challenge: To maintain log file disk usage you have to accomplish 2 main points:

Proposed solution: A solution to this is possible today already via logrotate: https://www.traccar.org/forums/topic/log-file-size/#post-72460

Also considered but much more effort: https://github.com/traccar/traccar/issues/3994 ^^ this might be another option but would required integration with a variety of syslogging products. It has to be considered that Traccar is used on other platforms apart from Linux+rsyslog.

Why logrotate? Logrotate or other similar log rotation mechanisms don't require complex integration and code change but mostly work out of the box.

What is missing: Yet there is one item that could be improved: Once a log file has been renamed (rotated) Traccar is required start writing into a new log file with the same name, so basically re-create the original (now empty) log file. Currently this can be achieved by restarting Traccar entirely but means an interruption of service and a potential loss of communication - especially on large systems.

So it is desired to have a functionality to send a signal to the running Traccar server which triggers the closing and re-creation of the log file while keeping the rest of the service running. Similar to how it is described here: https://github.com/log4js-node/log4js-node/issues/343

tananaev commented 2 years ago

Can you use console logger and just pipe it to syslog or some other external logging system?

twouters commented 2 years ago

You don't have to restart the traccar service if you add the copytruncate option to the logrotate config.