3

Yesterday I found that my Apache log file in my development machine was almost 50 GB in size.

Is there a way to limit the site of the Apache log file?

3 Answers 3

5

This is typically done using logrotate. Example logrotate configuration for Apache:

/var/log/httpd/*log {
    daily
    rotate 30
    compress
    missingok
    notifempty
    sharedscripts
    postrotate
      /bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true
    endscript
}
1
  • 2
    Mac OS 10.5 and up use newsyslog and the config file is located in /etc/newsyslog.conf. a man newsyslog and man newsyslog.conf should helped a lot!!
    – Onema
    Feb 18, 2011 at 18:27
2

For Mac OS X 10.6 Snow Leopard (10.6.8),
  following Onema's comment (on an answer),
  I added this line to /etc/newsyslog.conf(5) (with reformatted whitespace):

# logfilename                   [owner:group]   mode    count   size    when    flags   [/pid_file]         [sig_num]
/var/log/apache2/*_log          70:70           644     5       1000    *       JG      /var/run/httpd.pid

It instructs to rotate all logs (3 for me) 5 times each when over 1000 "kilobytes", using bzip2(1)

1
  • Note that the [owner:group], [/pid-file], and [sig_num] fields are optional and hence can be omitted.
    – Jeff Evans
    Jan 28, 2015 at 23:17
1

Building on Warner's suggestion, here's a logrotate config to delete your Apache logs if they grow larger than 5MB:

/var/log/httpd/*log {
    size=5M
    daily
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .