I've a log of a busy website that grows very fast. I'd like to know if there's a way to "split" the log file every day without using external tools.

EDIT: My Fault, I'm on a Windows server 2003, Apache Version 2.0.64.

link|improve this question

My answer below assumes that you have a Linux server not a Windows one! – Khaled Dec 9 '10 at 17:05
feedback

2 Answers

up vote 0 down vote accepted

Apache httpd is capable of writing error and access log files through a pipe to another process, rather than directly to a file. This capability dramatically increases the flexibility of logging, without adding code to the main server. In order to write logs to a pipe, simply replace the filename with the pipe character "|", followed by the name of the executable which should accept log entries on its standard input.

You can use this technique to pipe the logs to a script which then splits the logs in any way you like. This is often used to split by virtual host.

link|improve this answer
This is not what I would like to know... I mean: I thought that Apache was able to do it automatically... :( – IssamTP Dec 9 '10 at 16:38
@IssamTP - then why did you accept this answer? I agree, this is not the ideal way to accomplish log rotation unless you really need the flexibility that this provides. Go with Khaled's solution. – ErikA Dec 9 '10 at 16:51
Pretty hard to say in english: when I say "This is not what I would like to know" I mean that your answer brings bad news for me, not that you gave a bad answer. – IssamTP Dec 9 '10 at 17:15
Ahh, understood. Well, I'd still advocate that Khaled's solution is superior. With his solution, you would not have to write a custom log handler. – ErikA Dec 9 '10 at 18:11
No apache does not do this automatically and logrotate is the correct solution in most cases. I added the pipeing answer for completness as it is a useful technique if you need it, in most cases though you would not. I wrote the answer before I saw your meant a windows server I don't know the best answer in that case hopefully someone else does. – ollybee Dec 9 '10 at 18:44
show 1 more comment
feedback

You can use logrotate to keep your log files small and you can also compress them.

For example, you can use something like:

/var/log/apache/*.log {
      daily
      rotate 5
      size 100M
      compress
      postrotate
         /usr/bin/killall -HUP apache
      endscript
 }

This will keep five rotated files. The logs will be rotated daily and compressed. For more info, see man logrotate.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.