6

Not sure if this is possible at all.

And what about empty lines?

Update:

Testing the config with

logrotate -d /etc/logrotate.d/apache2

returns

error: /etc/logrotate.d/apache2:1 lines must begin with a keyword or a filename (possibly in double quotes)

for every empty line in the config file.

Original question about comment syntax is answered, though.

Update 2: This config now seems to work for me (note that it restarts apache after rotation):

/var/log/apache2/*.log {
    # https://stackoverflow.com/questions/26482773/apache-and-logrotate-configuration
    su root adm
    daily
    missingok
    rotate 14
    create 640 root adm
    # https://stackoverflow.com/questions/25845752/logrotate-suffix-dateext-rotate
    dateext
    dateformat -%Y-%m-%d.log
    sharedscripts
    postrotate
        systemctl restart apache2 || true
    endscript
}
Reto Höhener
  • 447
  • 1
  • 5
  • 8

1 Answers1

14
man logrotate

Note that comments may appear anywhere in the config file as long as the first non-whitespace character on the line is a #.

Ravexina
  • 54,268
  • 25
  • 157
  • 179
  • Hm ok thanks, I guess I was confused by the error I was getting, which I thought was because of my hash - error: /etc/logrotate.d/apache2:1 lines must begin with a keyword or a filename (possibly in double quotes). Will accept as soon as I get the config working. – Reto Höhener Aug 08 '18 at 19:30
  • 1
    try `sudo logrotate -v confName` it might help you diagnose the problem... – Ravexina Aug 08 '18 at 19:34
  • I am running `logrotate -d /etc/logrotate.d/apache2` as root to check my config, which got me the error. – Reto Höhener Aug 08 '18 at 19:43
  • My logrotate file would NOT tolerate any comments. But I'm on RedHat EL7. – Marcus Mar 19 '19 at 12:39
  • Examples are always helpful – barrypicker Apr 13 '23 at 16:15