Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Does apache2 support synchronized log for access_log and error_log? How the log in apache2 works for multiple instances? Will it get to lock condition if multiple instances write at the same time?

Thanks in advance.

share|improve this question
    
Thanks all for the answers. I am new in apache. Only proxy server function is used in our application and it has only access_log and error_log. From APR file_io write function I found it is using a pollset for log file descriptor if it can't do write. –  user111757 Mar 1 '12 at 3:01

4 Answers 4

Simply put, no, Apache itself does not lock files--at the very least, this is a performance and resource hit. At most, its a potential deadlock waiting to happen. Since there can be hundreds of threads on a normal setup vying for the lock, you'll see lots of starvation going on.

The more complicated answer is, you can certainly try and implement this yourself. That is, you can use something like piped logs to pass them an intermediary script that handles locking.

The right answer is, why do you need to put these into the same file? If they're hosting the same data, then they should be the same server--splitting it up into two separate overseers (i.e., root owned httpd) and multiple children for each (i.e., apache owned httpd) won't buy you anything; if anything, the additional resources required to launch resources will decrement performance. And if they're NOT hosting the same content, then they shouldn't be logging things to the same log.

If you absolutely do need the content to be merged, there are plenty of things out there that can merge the content from two Apache log files.

Hope this helps!

share|improve this answer

Does apache2 support synchronized log for access_log and error_log?
No. As others have pointed out, there is no locking or mechanism to ensure that entries are written in sync to any two apache log files. The events ARE however timestamped (so you can match an error_log event to the access_log event that triggered it), and tools exist to merge the logs if that's what you want to do.

How the log in apache2 works for multiple instances?
See the Apache manual section on logging, particularly the sub-section on virtual hosts.
Basically the answer is "It works however you configure it, within the limits described in the manual". The advice MrTuttle gave you (use a separate log for each site, and certainly separate logs for separate httpd instances!) is very good advice - I suggest following it...

Will it get to lock condition if multiple instances write at the same time?
No (see above), however you may experience some events written out of order into the log file under extreme load. (I've seen this ONCE, and the site was using piped logs, so it's possible the program that was handling the logs simply lost its mind...)

share|improve this answer

No, you won't getting a locking condition. Apache's logs aren't opened with an exclusive lock (i don't know if this is true on windows).

That said, use separate logs for your own sanity.

share|improve this answer

Multiple apache processes from the same instance can write to the same logfiles without any concern, because the fundamental IO API's guarantee this is safe (won't lose data or interleave) when a file descriptor is shared between N processes or threads.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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