Apache Better Log Rotation mod_log_rotate

Important: The Apache provided tool rotatelogs.exe is to buggy to use "for real", see: Apache Rotatelogs.exe for Windows Server

Using the module mod_log_rotate, the log rotation is handled by the server process so you save on the process count and file descriptors. I've compiled that code for windows using VC++ 6 for Apache 2.0.x and Apache 2.2.x. You can find the windows binaries of mod_log_rotate at the bottom of this article.

If you want to keep the names simple rename the downloaded file without the Apache version number it was compiled for like (mod_log_rotate.dll or mod_log_rotate.so). I made a dll version (mod_log_rotate.dll) and a dynamic Apache module version (mod_log_rotate.so). I use both versions on different Apache instances on the same server. If you have limited resource or very high traffic you might see a difference in performance. Please let me know any metric, if you experience real noticeable differences between the .dll and .so. The theory is the mod_log_rotate.dll might take a little more RAM but might be faster (load + runtime?).

To load this module, modify your httpd.conf:
LoadModule log_rotate_module modules/mod_log_rotate.so
#or if using the DLL version
LoadModule log_rotate_module modules/mod_log_rotate.dll
#Add the following line to use the module
RotateLogs On
RotateLogsLocalTime On


The directive for your individual sites custom logs, will not change:
CustomLog "E:/DomZeus/123test/W3SVC1383061124/ex.log" combined
Your log file will be in the format: ex.log.1140048000
The numeral is the number of seconds since: 01-01-1970

To translate that number into a date, the equation is: 01-01-1970 + 1140048000 seconds


mod_log_rotate directives

RotateLogs On|Off
Enable / disable automatic log rotation. Note: On Apache 2, once enabled mod_log_rotate takes responsibility for all log output server wide even if RotateLogs Off is subsequently used. That means that the BufferedLogs directive that is implemented by mod_log_config will be ignored. As BufferedLogs isn’t document and is flagged as an experimental feature this shouldn’t be a problem in production environments. This doesn’t apply to the Apache 1.3 version of the module.
RotateLogsLocalTime On|Off
Normally the log rotation interval is based on UTC. For example an interval of 86400 (one day) will cause the logs to rotate at UTC 00:00. When this option is on, log rotation is timed relative to the local time.
RotateInterval <interval> [<offset>]
Set the interval in seconds for log rotation. The default is 86400 (one day). The shortest interval that can be specified is 60 seconds. An optional second argument specifies an offset in minutes which is applied to UTC (or local time if RotateLogsLocalTime is on). For example RotateInterval 86400 60 will cause logs to be rotated at 23:00 UTC.

AttachmentSize
mod_log_rotate.dll for Apache 222 version 08_200644 KB
mod_log_rotate.so for Apache 222 version 08_200624 KB
mod_log_rotate.dll for Apache 2055 version 08_200644 KB
mod_log_rotate.so for Apache 2055 version 08_200624 KB
mod_log_rotate.dll for Apache 2059 version 08_200644 KB
mod_log_rotate.so for Apache 2059 version 08_200624 KB
mod_log_rotate.dll for Apache 223 version 08_200644 KB
mod_log_rotate.so for Apache 223 version 08_200624 KB


apache 2.0.63 log file time stamp issue

i see this in my /logs folder: access_log.txt.1211464140
i want this: access_log_05_23_2008_12_22_20.txt

you see the second type is human readable

my code is:

LoadModule log_rotate_module modules/mod_log_rotate.so
RotateLogs On
RotateInterval 60
CustomLog logs/access_log_ex%y%m%d.txt combined

whats up with the strange timestamp? i thought we can customize this?

you have to change customlog

Try change
CustomLog logs/access_log_ex%y%m%d.txt combined
to
CustomLog logs/access_log_%m_%d_%Y_%H_%i.txt combined

Module doesn't load with Apache 2.2.6 on Windows 2003

Hello,

I had used this module (and happy with it) on another platform. Now when I try loading it with Apache 2.2.6 on a W2003 server, it doesn't load. Would you have a version for this platform?

Thanks!
Michael

PS: your captcha system doesn't work when using IE7. I had to use Firefox to post this comment

What version of PHP are you

What version of PHP are you running? ...make sure to get the right eA version for your PHP version.

I'm not yet running Apache 2.2.6.
Anyone running Apache 2.2.6 + PHP 5.2.5 with eAccelerator?

Thanks,
Chris

Yes me. Apache 2.2.6 from

Yes me.

Apache 2.2.6 from apachelounge.com, PHP 5.2.5 and eAccelerator DLL from here

:D

Everything looks fine.

Thanks Al. Michael, using

Thanks Al.

Michael, using FileMonitor check the DLLs that are actually loading when you start Apache...you might notice some older PHP DLL in your path.

testIE7

testIE7

captcha works fine in my IE7...

I 'm using Jira in Tomcat

I 'm using Jira in Tomcat server, so could anyone please tell me how to use above utility in tomcat server.

Hi, I don't this will work

Hi,

I don't this will work with Tomcat unless it has binary compatibility with Apache modules.

Give it a try:
1) Load the module in your equivalent to httpd.conf
LoadModule log_rotate_module modules/mod_log_rotate.so
#or if using the DLL version
LoadModule log_rotate_module modules/mod_log_rotate.dll

2) Active the module in your equivalent to httpd.conf
RotateLogs On
RotateLogsLocalTime On

Now if you server starts up it's looking good. The last step is to check that you have a new log after midnight.

Good luck,
Chris

Hi Chris,

Hi Chris,
thanks for comment.
But i couldn't find httpd.conf file in tomcat.
Where in tomcat i plugin this utility.
how to check it's working or not.

Could you please help me in these issue.

Thanks in advance,
Regards,

Hi Abhi, My guess is that,

Hi Abhi,

My guess is that, if you want to use Apache modules with Tomcat you probably have to use The Apache Tomcat Connector. But I've only configured Tomcat a few times so I have very little expertise with that product.

I don't think Tomcat has a httpd.conf file. The conf files for Tomcat are usually in the folder "conf" like "E:\Tomcat4\conf". The configuration file have .xml and .properties extensions.

Good luck,
Chris

Will ErrorLog rotation be

Will ErrorLog rotation be added into a future release? Or did I miss a config option or something with the current release? I'm using Apache 2.0.55.

Thanks!

Unfortunately Apache error

Unfortunately Apache error logs are handled in such a way that we can’t work the same log rotation magic on them. Like transfer logs they support piped logging though so you can still use rotatelogs for them.

sorry.. but

Does this only rotate the access log?
I can't see it's doing anything to all the other logs..

If it's possible (and it probably is) could you compile one that rotates
referer log, agent log and error log too?

Maybe I just forgot something :)

This module only rotates

This module only rotates access logs.

For changes to the code ask the author directly. I will then recompile.

Added strftime() formatting

Bonjour :)

I've updated mod_log_rotate to support arbitrary date and time formatting in the generated log file name in the same way rotatelogs does.

This is great!!!

Just one question,

How exactly do I write this in the conf file?

Thanks,
Taff

Try something

Using Notepad, try something like:

CustomLog "E:/DomZeus/123test/W3SVC1383061124/ex%y%m%d.log" combined

I'm not sure if the log format "combined" is standard, if not you can define it with:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined

Arbitrary date directive

Can you direct me to a reference on how to use the arbitrary date feature in mod_log_rotate? I'm using Apache 2.2.2 on Windows.

Thanks.

Here is a start:

Here is a start:

At Apache Logs look towards the middle. The paragraph starting with 'log rotation "ala" IIS'.

mod_log_rotate new version

The new version is compiled based on code from August 2006 (08_2006).

The new feature is: "support arbitrary date and time formatting in the generated log file name in the same way rotatelogs does"

Thanks for this great module Andy !

Mod_Log_Rotate for Apache 2.0.53 ?

Hi Chris,

I was interested in Andy's latest module that allows common dates in the logfile name.

It looks like everything for mod_log_rotate will only work with versions 2.0.55 or 2.2.2.

I am stuck with Apache 2.0.53 due to Apache being part of my Netegrity Reverse Proxy product.

Is there anything out there for me to use? I was using Chronolog but ran into the problems you described.

Thx,
Jon Kaiser

I too am looking of a

I too am looking of a version of the latest mod_log_rotate to work with apache 2.0.x (specifically 2.0.58)

I am able to get the "mod_log_rotate.so for Apache 2055 version 04_2006", version running fine, but it doesnt support arbitary dates like the later version does.

Thanks in advance if you can help!

Barry

New mod_log_rotate for 2.0.x

New mod_log_rotate for 2.0.x.
This uses the August update to mod_log_rotate.c

Jon, I'm not sure how much

Jon,

I'm not sure how much changed between 2.0.53 and 2.0.55.
Try the 2.0.55 version.

Let us know if it works.
Thanks,
C

Merci Andy ! Will be

Merci Andy !

Will be compiling the new code soon...