0

I have a log folder under under /var/USER/mylogs and there on a daily basis log files in format "DATE-mylogile.log". DATE is formatted as "%d-%m-%Y".

So in my folder i have for example these log files:

12-01-2024-mylogfile.log
13-01-2024-mylogfile.log
14.01-2024-mylogfile.log
...

Now i want to use logrotate to rotate the logs. My test-Configuration looks like this:

/var/USER/mylogs/*.log {
weekly
rotate 4
compress
missingok 
dateext 
dateformat -%d-%m-%Y
}

But when logrotate runs it creates and gz-Archive for every single log file like:

12.01-2024-mylogfile.log-12-03-2024.gz
13.01-2024-mylogfile.log-13-03-2024.gz
14.01-2024-mylogfile.log-14-03-2024.gz

But i want that logrotate creates weekly one gz-Archive which includes all the single log files from the week, so that there is only one gz-Archive like:

mylogfile.log-14-03-2024.gz

But there i'm stuck - so is it possible and how can i do this?

1 Answer 1

0

After a little bit more of research i found a post serverfault where the answer is given.

So it is not possible to rotate logs with time/date in the filename. logrotate is designed to use a log file which is everytime the same and the application writes on this single log file.

Answer from linked serverfault post:

"If you're already creating the files with the date in the name, logrotate isn't the answer; it is based around the idea of the application always writing to the same log file (e.g. /var/log/app/output.log), and then logrotate takes care of renaming/compressing the files and telling the app to re-open the original target file again."

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.