1

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
}
  • 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. – 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
0
+100

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.

  • 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 0:18
0

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
0

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
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.