tags:

views:

208

answers:

4

I am in the process of setting up user action logging for my PHP site.

Would you recommend storing them in mysql or in text/log files?

A: 

I would recommend MySQL since it is then easier to view the log in for example an administrative area. You could then also set different flags, ie error levels, and filter through the log to find interesting items. Also you could easily base a statistics function on this data, much easier than whan in log files.

But I guess it depends on how you should use your log, and by whom they should be used. Raw log files are a bit geeky :)

eckberg
+3  A: 

Depends on what you want to do with those, I'd say :

  • If you need to get data from the logs, storing them in MySQL might help
  • If you only need to have some data you almost never use (but need in case of something illegal is done on your site, or stuff like that), a file might be well enough

To not slow things down too much, you can also use both (I've used that on some websites with a bit of traffic, where it wouldn't have been wise to store data in DB immediatly) :

  • during the day, store the logs in a file
  • and once a day (or once an hour, you get the idea), use a batch to parse those files, and put the data in Database

This way, you don't insert data in DB all the time ; and you can (provided a day or an hour has passed) do all the queries you need

Pascal MARTIN
Depending on your application design, opening a file and writing to it might not be that much faster than making a database query over an already established connection, though.
n3rd
indeed ; also depends on the load of the DB server, I guess
Pascal MARTIN
I would just add that, for best results, if your logging functions write to a database, you really should also have a fallback so that, should the database connection fail the logs are written to a flatfile. Otherwise, your site/application may fail and, as your only logs are in the database, if that fails you don't get anything.
Lucanos
+1  A: 

I would recommend using something like Zend_Log to abstract from the actual 'physical' logging. That way you can always change backends later very easily, in case your situation changes for some reason or another.

n3rd
A: 

Most log analysis tools need raw log file to parse. If you are looking at the logs themselves, a db might be better (with the conditions pascal said). But if you plan to do some real analysis, it will be easier to use log files.

Byron Whitlock