Search code examples
loggingapache

How can I limit the size of Apache's access_log, and limit the number of archived logs it keeps?


Apache's access_log file rotates out into an archived copy around 1GB every few days. Where are the settings to control this? I'd like to be able to control both the max size and the number of archived logs it keeps around. Is this part of apache's configuration, or do I need to write cron jobs ( et al ) to deal with this? I'm running pre-forked httpd.


Solution

  • On most Linux distributions, the system is set up to run logrotate on a daily basis. You won't see it in the crontab for root or for any particular user.

    It's easy to change how it handles log files. On my Ubuntu server, the /etc/logrotate.conf file has settings like these:

    # rotate log files weekly
    weekly
    
    # keep 4 weeks worth of backlogs
    rotate 4
    
    # create new (empty) log files after rotating old ones
    create
    
    # uncomment this if you want your log files compressed
    #compress
    

    [etc.]

    And, you can look in the directory /etc/logrotate.d/ to see settings for specific directories and apps.