0

Apache 2 has rotatelogs, which seems to do what is says, which is, allow me to define a location and a pipe for a virtual host, and have, in this case, the error_log rotated by size, or by time.

I am on OS X, and logrotate is not available, looks like syslog is used, but Apache is not logging to syslog in this case, nor do I believe that would be what I want to do. If I have syslog take over, it will rotate, zip, email, and much more, but I then have to hup Apache, I believe that is a little brute force.

I am only working on error_log today, and would like a log file that is 200K in size, then rotated. rotatelogs takes 1M as a value, can I use something like .2M?

Another reason I believe syslog would not work, is that I would then have to define a line in the syslog config settings every time I add a new virtual host.

With Apache's rotatelogs, there are two issues:

1) Logs have root owner, is there any way to define what the owner is, or any of the permissions for that matter?

2) There are hundreds of virtual hosts, I want to keep 10 logs or so, and then delete the rest. Is this usually solved with unix find and gzip and rm, etc.?

Summary: I have /path/www/lastname.firstname/logs/ where lastname.firstname will be hundreds of directories. error_log needs to go to the logs directory for that lastname.firstname. I am looking for how to make sure these log files do not get too large and out of control. I actually want them very small, so users can quickly download them and see errors while they are developing. Users will not be given shell access, so they cannot use something like tail -f on the logs.

2 Answers 2

1

Why not just install logrotate on your OS X server? It's a Unix, logrotate works on Unices... the two were practically made for each other.

0

I'll heartly agree to use logrotate program to handle the situation. The logrotate package generally has an apache log rotater example. However, you will find that in general it does the following: (1) rename the log file(s), and then (2) issue a non-fatal kill command so that apache closes the current log files and creates new ones. It is possible that for a small window of time after the kill command (which is trying to be nice to your users) that log data will be placed in the old log files.

A couple of other practical points on using the piped log rotate function:

  1. The consumption of an additional process per each log file. If you already have a lot of processes this could be problematic.

  2. Of course the use of more total open file handles which can of course be configured.

  3. I've had the experience where not everything dies correctly during an apache server shutdown. This was a long time ago however. But it also makes simply killing the apache process with -9 sometimes problematic leaving zombies out there.

BTW, I've personally ported the logrotate package to different UNIXen/Linuxen systems easily.

Enjoy!

2
  • Thanks, everyone keeps pointing me to this app, yet I can not find any new news about it for years now. Is it just that good, and that bug free, or is it one of those apps that is simple enough it probably does not need udating? I am literally seeing years in which there has been no activity on this. Any ideas why I would chose this over apache's built in rotatelogs?
    – Anonymous
    Oct 13, 2009 at 4:07
  • If if ain't broke, don't fix it. Oct 11, 2015 at 15:36

You must log in to answer this question.