2

I want to create daily logs, but there's a small problem. Logs aren't being created for each day, rather they contain the previous log files. Here's my current setup, how can I change it so it only create a log file for each day?

I edit the following file : /etc/logrotate.d/httpd

I'm using a control panel called Zadmin so I included its log path as a second dir.

I'm using CentOS 6.5 64 bit.

/var/log/httpd/*log /var/sentora/logs/domains/zadmin/*.log {
    missingok
    rotate 4000000
    daily
    notifempty
    sharedscripts
    postrotate
    /sbin/service httpd reload > /dev/null 2>/dev/null || true
    endscript
}
salep
  • 35
  • 1
  • 1
  • 8
  • What do you mean by > they contain the previous log files – c4urself Aug 21 '15 at 18:30
  • For instance, when I look at the access.log file, it includes all the logs that has been created so far. I don't want it, I want it to create logs daily and name it like the following : access.log-21-08-2015 – salep Aug 21 '15 at 18:31
  • There is also a rotate logs program that comes with Apache, [rotatelogs](http://httpd.apache.org/docs/2.4/programs/rotatelogs.html). – Brian Aug 21 '15 at 18:37
  • Is this happening only to Apache logs? If its happening to all logs the 'create' option might be missing from /etc/logrotate.conf (please add the content of that file to your post). Also the /var/lib/logrotate.status (I think Centos has that one, at least Arch has it) might be corrupted, you could try and move it out of harms way and try running logrotate -f /etc/logrotate.d/httpd manually as root. Also adding the -d switch for debugging purposes wont hurt. – ojs Aug 21 '15 at 18:45
  • Do you have cron task which runs logrotate? what happens when you run logrotate /etc/logrotate.conf manually? – Navern Aug 21 '15 at 19:22
  • WAG: There is an error in the apache configuration so the reload isn't working. Try `apachectl configtest` – Mark Wagner Aug 21 '15 at 21:05

3 Answers3

2

Apache lets you pipe log files to another program which can then handle rotation without having to reload/restart Apache. Apache even provides a program to do this.

ErrorLog "|bin/rotatelogs -l -f /var/log/apache2/errlogfile.%Y.%m.%d.log 86400" common
CustomLog "|bin/rotatelogs -l -f /var/log/apache2/logfile.%Y.%m.%d.log 86400" common
Brian
  • 3,476
  • 18
  • 16
  • ErrorLog has an issue in the format. ErrorLog takes one argument, The filename of the error log - no "common" is expected in the end of the line. Apache fails to start with such config. – Hardoman Nov 24 '20 at 17:35
  • Moreover, you need to specify the real path to rotatelogs. Normally it's not like above but can be /usr/local/apache/bin/rotatelogs – Hardoman Nov 24 '20 at 17:53
  • @Hardoman The examples are from the documentation: [rotatelogs - Piped logging program to rotate Apache logs](https://httpd.apache.org/docs/2.4/programs/rotatelogs.html#examples) – Brian Nov 24 '20 at 18:18
  • 1
    And you copied it incorrectly. ErrorLog doesn't have "common" in the examples! – Hardoman Nov 27 '20 at 10:06
2

Try running logrotate manually to look for errors: logrotate -d /etc/logrotate.d/httpd. The manual says "-d Turns on debug mode and implies -v. In debug mode, no changes will be made to the logs or to the logrotate state file."

This is what we're using successfully:

/var/log/httpd/*log {
  daily
  dateext
  dateformate -%d-%m-%Y
  missingok
  nocompress
  rotate 30
  postrotate
    /sbin/service httpd reload > /dev/null 2>/dev/null || true
  endscript
}
miken32
  • 942
  • 1
  • 13
  • 35
1

Following on to Brian's answer, I'm a big fan of cronolog, which does pretty much exactly what you're going for:

CustomLog "|/usr/sbin/cronolog /var/log/httpd/%Y/%m/%Y-%m-%d-access.log" combined
ErrorLog "|/usr/sbin/cronolog /var/log/httpd/%Y/%m/%Y-%m-%d-error.log"

yum install cronolog will get you cronolog on Cent6.

BMDan
  • 7,249
  • 2
  • 23
  • 34
  • It does look nicer than the Apache program, would just add it is in the EPEL repository which is not enabled be default on CentOS (`yum install epel-release` to install/enable it). – Brian Aug 21 '15 at 19:11
  • Where I should put the text that starts with "CustomLog" and "ErrorLog", /etc/logrotate.d/httpd? – salep Aug 21 '15 at 19:42
  • Additionally, should I remove everything in the /etc/logrotate.d/httpd and just put these? – salep Aug 21 '15 at 19:48
  • They go in the Apache web server's configuration file. – Brian Aug 22 '15 at 00:18