I'm developing a sort of web application and recently come a need to log some of user activities in it. Therefore come with natural question is it a good idea to use Apache server logging mechanism for that? If the answer is yes, please explain why and so if not. Mine main concern is reduction in performance as a result of enabling logging in Apache. As well, what is the best practice for building logging mechanism in order to be able to track client activity in web based application?
Apache is simply appending text to a log file - it isn't much of a performance penalty. Also, there is an excellent chance that you have logs enabled already, since that's how most of the statistics packages installed on a web host work (unlike web-based Google Analytics etc.)
If you have a single server, a separate log file would be my choice. I like to keep application logs separate from web server logs, because it is easier to find relevant records that way.
If you have multiple servers and want to have a common log, you might want to look into syslogd et al. to send log data from your application servers to a single logging machine.
Keeping a log in database is also possible, but may cause a significant load on the database servers, especially if your application already relies on caching to keep database load low.
As MaxVT said, it is highly unlikely that the overhead of logging would impact performance. The overhead of network latency in a web application is generally far greater than a single disk write, which can be in the single-digit microseconds range.
Generally, web based applications should always have some form of logging turned on, and the mod_logger based logs in Apache is a very cheap way of doing it.
While apache logging is very performance-cheap, you need to consider the uses of the logs:
- Will the user be able to see "My Log"?
- Do you need "rollback" based on the log?
- Do the kind of actions you log have associated data?
These questions can lead you to chose either apache logging, or a DBMS-based custom logging.
Using custom logging, you can easily build transactional logs that can help you revert your whole system from one state to another with as much as a click.
jrh