PHP logs - mysql vs file

I start action logging for my PHP site.

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

+4
source share
4 answers

Depending on what you want to do with this, I would say:

  • If you need to get data from logs, storing it in MySQL can help.
  • If you need only some data that you almost never use (but you need something illegal to be done on your site or something like that), the file can be quite good.

In order not to slow down too much, you can also use both (I used this on some sites with a small amount of traffic, where it would be unreasonable to store data in the database immediately):

  • during the day, save the logs in a file
  • and once a day (or once an hour, you get an idea), use a batch to analyze these files and put the data in the database

Thus, you do not insert data into the database all the time; and you can (provided that a day or hour has passed), all the requests that you need

+5
source

I would recommend using something like Zend_Log to abstract from the actual "physical" logging. This way you can always easily change the backends later if your situation changes for one reason or another.

+1
source

I would recommend MySQL, since then it is easier to view the log, for example, the administrative area. Then you can also set various flags, i.e. error levels, and filter through the log to find interesting objects. You can also easily create a statistics function for this data, much easier than in the log files.

But I think it depends on how you should use your journal and who should use them. Raw log files are a little ugly :)

0
source

Most log analysis tools require a raw log file for parsing. If you look at the logs yourself, db might be better (with the terms pascal said). But if you plan to conduct a real analysis, it will be easier to use the log files.

0
source

All Articles