Page 1 of 1

Solved: Rotate apache logs in windows

Posted: Thu Sep 11, 2008 8:46 pm
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.

Re: Rotate apache logs in windows

Posted: Fri Sep 12, 2008 8:51 am
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

Re: Rotate apache logs in windows

Posted: Fri Sep 12, 2008 4:59 pm
by Peter_w
I tried your solution.

But when i add the line, the server doesn't want to start.

Re: Rotate apache logs in windows

Posted: Sat Sep 13, 2008 2:01 pm
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/)

Re: Rotate apache logs in windows

Posted: Mon Sep 15, 2008 8:40 am
by Peter_w
I added common,
and the server now starts, but it doesn't seam to update the log-file.

Re: Rotate apache logs in windows

Posted: Fri Sep 19, 2008 3:35 pm
by chris
Perhaps if you add the full pathname of the log file?

Hi, buddy, thanks for your article.

Posted: Mon Oct 06, 2008 2:58 pm
by iHydra
this article help me a lot, I am very aprreciated for it. thank you very much.

Re: Rotate apache logs in windows

Posted: Thu Jan 08, 2009 9:07 pm
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

Re: Solved: Rotate apache logs in windows

Posted: Tue Feb 03, 2009 12:46 pm
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 ...