While running apache server one of the typical problems faced is how to make a backup of the log files per day or when the size exceeds a particular limit.
Problem:
If you have an apache server running over a month and various users using the system, the error.log and the access.log files become huge(mine was about 670MB). This creates problem to readability and system security. We need a mechanism by which apache can manage its own log files.
Solution:
In unix there is a piped system where the user can direct the error logs to a script which will write the errors in a particular log.
Windows installation of apache comes with a program called rotatelogs.exe which can be found in the bin directory of the Apache Folder.
This explanation is only for windows version of apache.
How to make the access log rotated ?
In the httpd.conf file , look for a variable called CustomLog
Typically it will be given as
CustomLog "logs/access.log" common
Change the line to
CustomLog "| bin/rotatelogs.exe logs/access%Y_%m_%d_%H_%M_%S.log 86400 -300" common
This will create a separate access file each time you start the server. If the server is running for more than a day or if the access file size has exceeded more than 300MB, it will create another access file.
Explanation :
logs/ the folder which will contain all the log files
access -> the initial name of the file to be kept so that you know its the access log
%Y_%m_%d_%H_%M_%S -> The time stamp created to keep the file unique and readable so that you know when it was created
86400 - delay in seconds unitll which there shall be no file created
300 -> the limiting size of the file in MB
Similarly for an error log file also
ErrorLog "| bin/rotatelogs.exe logs/error%Y_%m_%d_%H_%M_%S.log 86400 -300"
This command will create the error file once the server starts.
Note that the CustomLog has a common at the end and ErrorLog doesnot have it. This has created an error to me while doing the configuration.
quite usefull if you want to maintain a precise information for errorlogs in your server.