Apache logs generate files by date to limit the log file size

Source: Internet
Author: User
Tags apache log

Let's take a look at how to configure logs regardless of the date size.

The code is as follows: Copy code

LogFormat "% h % l % u % t" % r "%> s % B" % {Referer} I "" % {User-Agent} I "combined
CustomLog "E:/1408.log" combined

The generated access log is too large and later than 100 GB, so it cannot be viewed. This is certainly not the way to search for the log storage by size.

The code is as follows: Copy code

# Restrict the error log file to 1 MB
ErrorLog "| bin/rotatelogs.exe-l logs/error-% Y-% m-% d. log 1M"

# Generate an error log file every day
# ErrorLog "| bin/rotatelogs.exe-l logs/error-% Y-% m-% d. log 86400 & Prime;

# Restrict access log files to 1 MB
CustomLog "| bin/rotatelogs.exe-l logs/access-% Y-% m-% d. log 1M 1M" common

# Generate an access log file every day
# CustomLog "| bin/rotatelogs.exe-l logs/access-% Y-% m-% d. log 86400 & Prime; common

This is simple. Just put it in. The error log is shown below.

This section describes windows users. linux uses cronolog to separate apache logs.

The cronolog tool can be run in linux or on a windows host. The installation method of linux is very simple. You can do it by using make install. The setting method is the same after installation, the following describes how to configure a windows host.


Copy the cronolog.exe tool to the apachebin directory.
■ 2. Modify the httpd. conf configuration file and find the mlog line.
■ 3. Modify it to the following format: CustomLog "|/usr/www.111cn.net/sbin/cronolog/usr/local/apache/logs/% Y _ % m _ % d. access. log" combined
Here, logs are generated every day.
Here,/home/apache/logs indicates the path where your log is stored;/usr/local/sbin/cronolog indicates the path where cronolog is located, which can be viewed using the which cronolog Command; % Y _ % m _ % d indicates that the log files are separated by year, month, and day, so that a log file is generated in one month. If you want to generate a log file every day, it seems to be % Y % m % d
Restart apache and you will find that apache logs are generated by date, and the original apache log files will no longer record new access data.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.