How to specify exceptions from wildcard settings in a logrotate configuration file?

Solution 1:

The most elegant answer is to put thatonespecial.log in a separate directory so it wouldn't be able to match the wildcard.

If that won't work, then you can use globs to narrow down your wildcard. It's messy, but if you absolutely can't move the file location then it's probably your only real option. Something like this:

/var/log/mylogs/[!t][!h]*.log

Would match any .log files with at least 2 characters in their name that don't start with "th".

Solution 2:

It seems that the overwriting of rules was implemented and it works now:

$ logrotate --version
logrotate 3.8.7

$ cat /etc/logrotate.d/test
# rotate application logs for 40 days by default
/home/myapp/log/*.log
/home/myapp/log/*/*.log
{
    daily
    compress
    delaycompress
    rotate 40
}

# rotate access logs for 1 year
/home/myapp/log/access/*.log {
    daily
    compress
    delaycompress
    rotate 365
}

$ logrotate  -d /etc/logrotate.d/test
reading config file /etc/logrotate.d/test

Handling 2 logs

rotating pattern: /home/myapp/log/*.log
/home/myapp/log/*/*.log
 after 1 days (40 rotations)
empty log files are not rotated, old logs are removed
No logs found. Rotation not needed.

rotating pattern: /home/myapp/log/access/*.log  after 1 days (365 rotations)
empty log files are not rotated, old logs are removed
No logs found. Rotation not needed.

While when tested on my local logrotate (version 3.7.8) the error was raised:

$ cat logr.conf 
# rotate application logs for 40 days by default
/home/myapp/log/*.log
/home/myapp/log/*/*.log
{
    daily
    compress
    delaycompress
    rotate 40
}

# rotate access logs for 1 year
/home/myapp/log/access/*.log {
    daily
    compress
    delaycompress
    rotate 365
}

$ logrotate -d logr.conf 
reading config file logr.conf
reading config info for /home/myapp/log/*.log
/home/myapp/log/*/*.log

error: logr.conf:12 duplicate log entry for /home/myapp/log/access/api_access.log
error: found error in /home/myapp/log/access/*.log , skipping
removing last 1 log configs

...