I have a custom logging class that creates a log for each instance of the process and adds a unique id to the log file name, example:
- process.1234.log
- process.1235.log
Also I can add a date/time stamp as well, example:
- process.1234.03012012.log
- process.1235.03012012.log
Does LogRotate have the ability to use a regex so I could archive my log files by date and/or process id?
Best Answer
I don't know if later versions do, but after researching further I found that shell wildcards are supported. Both
*
(match multiple characters) and?
(match a single character) can be combined to match specific files.As an example, here are patterns which match your use case along with the rest of a file which could be found at
/etc/logrotate.d/process
However if you intended for
process
to be a placeholder for an actual process id, then I believe you can get away with using a wildcard in place of the process id number like so:I hope this helps. I too went searching for a regex approach that would work and finally decided on the use of shell wildcards instead of what I felt were workable, but more complex solutions.
An example:
While searching for a regex solution I found a blog post titled, "Excluding files from logrotate globbing matches" which provided this solution:
I ended up pulling two items out of that example and modified the match slightly. In my situation I wanted to rotate all files in a directory except for some input files which have a
.inp
extension.This is what I came up with:
According to
logrotate -d /etc/logrotate.d/myfilename
it appears to work. However as I mentioned I opted for the shell wildcards approach as it seemed easier for someone coming behind me to maintain.