Limit Apache log file Access.log size method

Source: Internet
Author: User
Tags apache log file file size local time time interval apache log

Rotatelogs Gadgets with Apache

The syntax is as follows:

Rotatelogs [-l] logfile [rotationtime [offset]] | [Filesizem]

Parameter explanation:

-L: Use local time instead of GMT time as a time benchmark. Note: using-l in an environment that changes the GMT offset (such as daylight saving time) can lead to unpredictable results.
LogFile: It plus the reference name is the log file name. If logfile contains "%", it will be treated as a format string for strftime (), otherwise it will be automatically added in seconds

Bit of the ". nnnnnnnnnn" suffix. Both of these formats indicate when the new log is to be used.
Rotationtime: The time interval in seconds that the log file scrolls.
Offset: The number of minutes of time difference relative to UTC. If omitted, it is assumed to be "0″ and use UTC time." For example, to specify local time for a region that has a UTC difference of "-5 hours", this parameter

should be " -300″."

Filesizem: Specifies to scroll in filesizem file size, rather than by time or jet lag.

Example:
1, scrolling log files by time:

The code is as follows Copy Code


Error log: ErrorLog "|/data/apache/bin/rotatelogs log storage directory/%y%m%d_error.log 86400 480″
Access log: Customlog "|/data/apache/bin/rotatelogs log storage directory/%y%m%d_access.log 86400 480″common

which

/data/apache: For Apache installation directory, according to their actual situation to determine;
86400: Seconds, 24 hours, indicates that the generated log files are scrolled by day, that is, to generate a log file every day;
480: Minute, time offset.
Similarly can scroll log files by the hour, every one hours, a few hours ... Generate a log file.

Extensions: You can write a script to delete log files, only a few days of log, if the site traffic is larger, one day will generate dozens of hundred m or even larger log files, both the hard disk and affect server performance.

2. Scroll log file by size:

The code is as follows Copy Code

Error log: ErrorLog "|/data/apache/bin/rotatelogs-l log storage directory/%y%m%d_error.log 5M"
Access log: Customlog "|/data/apache/bin/rotatelogs-l log storage directory/%y%m%d_access.log 5M" common

Scrolls the log file when it reaches 5M.

Examples of settings under Windows are as follows:

The code is as follows Copy Code


# Limit error log file to 1M

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"

# Restrict access log files to 1M

Customlog "|bin/rotatelogs.exe-l logs/access-%y-%m-%d.log 1M" common

# Generate an Access log file every day

#CustomLog "|bin/rotatelogs.exe-l logs/access-%y-%m-%d.log 86400" common

The setup examples under Linux are as follows:

  code is as follows copy code

# limit error log files to 1 m

ErrorLog "|/server/apache/bin/rotatelogs/server/apache/logs/error-%y-%m-%d.log 1M"

# generates an error log file every day

ErrorLog "|/server/apache/bin/rotatelogs/server/apache/logs/error-%y-%m-%d.log 86400"

# restricts access log files to 1M

Customlog "|/server/apache/bin/rotatelogs /server/apache/logs/access-%y-%m-%d.log 1M" Common

# Generate an Access log file daily

Customlog "|/server/apache/bin/rotatelogs /server/apache/logs/access-%y-%m-%d.log 86400" Common

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.