What is the best way to store access logs. TXT or Database? [duplicate]

-1

I have always stored the access logs in the database, but I have noticed that a colleague stores in a txt and opened that discussion on how best to store this information for future reference if necessary and taking into account good practices, storage , etc. Anyway, what is the best way to store access logs? Database or TXT?

    
asked by anonymous 28.12.2018 / 16:36

2 answers

1

In very general terms, the record in a text file is much faster than the record in a database. That is the main factor you should consider. The reason people create logs in a database would be to have easier queries, that is, database is easier, especially if you record contextual information that can be used to group log entries. It is also generally easier to access a central database than a log file on a server that can be secured and not accessible. The ideal would be to register locally to a file and if you need to migrate this data to a DB for inspection.

    
28.12.2018 / 16:47
0

The choice of how an application manages the logs is relative.

The best way is the one that has the least impact on your application or has a lower infrastructure cost.

Saving logs to the database makes data manipulation more flexible and accessible, including automating backups.

Another reason is that it has much longer durability and is in a supposedly more secure location than the DB.

Not to mention that it can be accessed from anywhere in the application if there is a page that lists the log data.

But there is a problem with that. Depending on how the log is implemented in your application saving it to the database can make it easier to create a bottleneck.

Exemplifying:

Imagine that you have entities that relate to the application and that every time that certain operations are performed, you need to log a database log next to that operation, and suddenly application performance begins to fall on account of the coupled generated between the log and the entities. And finally you end up having a performance bottleneck.

There are a few ways to get around this.

As for logging into files, depending on the size of the application can become very expensive to read.

Imagine a log file with at least 200mb in size? The processing power of the machine that will read this must be great.

Although logging is much faster in a file than in the database itself, a counterpart is generated in the sense of reading.

Another disadvantage of logging to a file is that it is not visible in an application, it does not have easy access.

In addition, you can register locally to a file, and then migrate that data to a database if necessary. Or keep the logs in files and in the database.

In any case, the best way to store logs will depend on the need, context, and infrastructure.

    
28.12.2018 / 17:07