restic / rest-server

Rest Server is a high performance HTTP server that implements restic's REST backend API.
BSD 2-Clause "Simplified" License
978 stars 143 forks source link

format the log file name to yyyyMMdd.log #186

Closed dmhai closed 2 years ago

dmhai commented 2 years ago

How can I format the log filename dynamically (e.g. yyyyMMdd.log), I need to read the log by date.

rawtaz commented 2 years ago

I presume you mean the log file enabled by the --log option to rest-server, correct? If yes, there's no feature in rest-server currently where it writes the log to a file that changes with the current date.

A workaround is that you run rest-server with e.g. --logdate +%Y%m%d.log, and simply restart it (with the same command) at 00:00 every night. Then you will get a new log file for every day. Make sure to rotate those files so they don't fill up your disk space in the end.

mafalb commented 2 years ago

logrotate is good for that, something similar to

/path/to/rest-server.log {
daily
dateext
postrotate
        /bin/systemctl reload rest-server.service
endscript
}

dateext is appending the current date to the rotated log file