When to write logs to database?

Posted on

Question :

I am part of a team that is developing an application using Zend framework 2 and MySQL database. We need to develop a logging feature of the actions performed by the users in order to enable audits by the application itself. We are a new team and this is the first time we will do something like that. I’m afraid to write the logs on a bench and the table gets too large.

Then my question: When is it appropriate to write logs to the database?

    

Answer :

(The question is somewhat broad and the answers will depend on the experience of each one.)

If you have the opportunity, log on to the BD:

  • Makes it easier to manipulate data;
  • Simple to clean and manage (automatic et al backups);
  • Has BD-guaranteed durability;
  • You can easily access BD over a network without having to share folders;

Note:

In case you have an application that will be on the client side, then I would say that it is preferable to log in both ways. The general logs in the DB but have logs in the file also (for the highest levels (Warning, Error, Fatal)) so that in case of problems, the client can send the files without having to know how to use the DB. / p>
    

Your question will likely be closed because it is opinion-based, but I believe I can answer something within the scope of the OS.

Fear, yes, but not because the table is large but rather optimizes it. A good example of optimization is to use indexes.

The problem is not to be big, if that were the way facebook would be in bad clothes, but the performance of its database / application.

Logs are not frequently queried (in the majority of cases), but will eventually be missed when, for example, something does not go as planned.

If you are afraid of leaving the user blocked while generating a log, do so in the background in the language you are using and leave the user free to continue using the application.

    

Leave a Reply

Your email address will not be published. Required fields are marked *