Solved: Rotate apache logs in windows

Questions related to the Apache server
Locked
Peter_w
Posts: 28
Joined: Tue Aug 19, 2008 9:28 am

Solved: Rotate apache logs in windows

Post by Peter_w »

Hello,

I have apache installed on Windows XP.
But the logs are getting quit big now.

Is there a way to rotate them, or overwrite them?
So they don't get to big? 100MB is really to much data.
chris
Site Admin
Posts: 205
Joined: Mon Jul 21, 2008 9:52 am

Re: Rotate apache logs in windows

Post by chris »

You can use rotatelogs.exe to manage the logs.

rotatelogs.exe can be found in the apache2/bin/

Code: Select all

CustomLog "| bin\rotatelogs.exe logs\access%Y_%m_%d.log 86400"
Should create a new log every day. (86400 seconds)

You can als create a new one on size:

Code: Select all

CustomLog "| bin\rotatelogs.exe logs\access.log 5M"
Create a new log file when the log file is larger then 5MB
Peter_w
Posts: 28
Joined: Tue Aug 19, 2008 9:28 am

Re: Rotate apache logs in windows

Post by Peter_w »

I tried your solution.

But when i add the line, the server doesn't want to start.
chris
Site Admin
Posts: 205
Joined: Mon Jul 21, 2008 9:52 am

Re: Rotate apache logs in windows

Post by chris »

Sorry, my mistake the full line should read:

Code: Select all

CustomLog "| bin\rotatelogs.exe logs\access%Y_%m_%d.log 86400" common

dont forget to set the root dir:

Code: Select all

ServerRoot "C:/Program Files/Apache Group/Apache2"
(Normally this is already done at the beginning of the file/)
Peter_w
Posts: 28
Joined: Tue Aug 19, 2008 9:28 am

Re: Rotate apache logs in windows

Post by Peter_w »

I added common,
and the server now starts, but it doesn't seam to update the log-file.
chris
Site Admin
Posts: 205
Joined: Mon Jul 21, 2008 9:52 am

Re: Rotate apache logs in windows

Post by chris »

Perhaps if you add the full pathname of the log file?
iHydra
Posts: 1
Joined: Sun Sep 21, 2008 12:10 pm
Contact:

Hi, buddy, thanks for your article.

Post by iHydra »

this article help me a lot, I am very aprreciated for it. thank you very much.
chris
Site Admin
Posts: 205
Joined: Mon Jul 21, 2008 9:52 am

Re: Rotate apache logs in windows

Post by chris »

Arch you need to put the slashes right,

This should work:

Code: Select all

CustomLog "| bin/rotatelogs.exe logs/access%Y_%m_%d.log 86400" common
chris
Site Admin
Posts: 205
Joined: Mon Jul 21, 2008 9:52 am

Re: Solved: Rotate apache logs in windows

Post by chris »

The logrotate that comes with Apache, doesn't zip or delete files.
I made a litlle bat-file that zips and delete the old zip files.

Code: Select all

@ECHO OFF

SET datum=%Date:~-4,4%_%Date:~-7,2%_%Date:~-10,2%
SET logdir=c:\Program Files\Apache Group\Apache2\logs\
SET holdzipfiles=7

::go to dir
cd %logfir%

::gets all the log files with 20 in from 2009 (will break in 2100, but by then you shouldn't be a beter system)
dir /B *20*.log | find /V "%datum%.log" > filestoarchive.dat
::If at first it doesn't work, it might be something with the quotes.


::Zip it, and delete old file
FOR /F %%a IN (filestoarchive.dat) DO (
"c:\program files\winzip\wzzip" -ex -u "%logdir%logs.%datum%.zip" "%logdir%%%a"
del "%logdir%%%a"
)

::del filelist
del filestoarchive.dat

::check zip  files
dir /B /O-D logs.*.zip > zipfiles.dat


::we hold the first ? files and delete the rest
FOR /F "skip=%holdzipfiles%" %%a IN (zipfiles.dat) DO (
del %%a
)

del zipfiles.dat

::the end
I let it run every month, but you can run it once a week, or ...
Locked