[ Team LiB ] |
Recipe 3.9 Rotating Logs on the First of the MonthProblemYou want to close the previous month's logs and open new ones on the first of each month. SolutionThe Apache distribution doesn't include a canned script to perform this duty, but you can find one on this book's companion site at http://Apache-Cookbook.Com/sources/Chapter04/rotate-log-monthly.pl. You use it by piping the desired activity log through the script, such as with: CustomLog "| rotate-log-monthly.pl logs/access_log-%Y-%M" CLF The argument to the script is the name of the logfile; the special sequences beginning with % are passed to strftime(3) to form the new logfile name. DiscussionAs with the other logging solutions in this chapter, the solution given here addresses a single specific need. If you want to combine functions, such as splitting logfiles according to virtual host and rotating them on the first of each month, you are going to need to use custom scripts. The rotate-log-monthly.pl script is a rather brute-force approach and may not be appropriate for extremely high traffic servers due to its sampling of the system time at each log entry. However, it illustrates the technique. See Also |
[ Team LiB ] |