Why are logs stored in flat files and not in a database (SQL)?

Why do web servers and other technologies use flat files for logging, and not some database, be it SQL or some kind of KVS or "NoSQL" solution?

Is there an advantage (speed, latency, recording time, etc.) for using flat files, or am I just missing something?

+4
source share
5 answers

You are not guaranteed to have a database on the server.

If the DB is part of the problem, how do you look at the logs.

If the database is not part of the problem, it’s still easier to view the logs with any old text editor.

Why use complicated when simple works. When Apache (etc.) was first developed, open (free, ubiquitous) databases were not available.

Etc. Etc.

+9
source
  • First of all, it is easy to write.
  • It's just ... writing to a file is one of the least likely errors.
  • Because of simplicity, it is fast. This applies to both writing to disk and CPU time to perform operations.

Many of them are also a legacy. While database servers and computers with 100-gigabyte storage, if not terabytes and gigabytes of RAM, abound, if not by standards, the most hardened servers are welcomed from the moment when memory was system resources, they were fully used by much less load.

But basically it's simple. Why rely on SQLite (as a simple built-in SQL service) to ensure that your license is compatible, that you support the appropriate versions, and that it does not have basic bugs or security issues ... to do nothing but sequential insertions?

KISS. Log analysis tools should not be part of a journal entry.

+2
source

There's an eternal principle that says that the fewer moving parts, the less points where something can go wrong. You minimize dependencies, thereby minimizing the places where errors can occur. It is also fast because it is simple and a high-load server that you do not want to register to intimidate the system.

Interestingly, the same principle that made Charles Lindbergh's single-engine aircraft a successful flight without a break across the Atlantic when many other large aircraft appeared in front of him. Keep it simple :)

+2
source

While the rest of the answers here are correct (the basic principle of KISS, etc.), I saw a project in which logging filled the server hard drive, and they had to create automation to clear the logs. To solve this problem, you may need to implement the backup / maximum log size scaling function or perform a scheduled task (cron) to move or delete logs.

No free lunch.

+1
source

That's why we stopped using database logs in my work.

try { tx.Begin(); // Exception here! tx.Commit(); } catch(Exception ex) { LogToDB(ex); tx.Rollback(); } 

Each time we had an exception connecting to the database, logging was rolled back.

(I guess I shouldn't say always ... Only when the rollback occurred after registration. However, this was a bit confusing!)

0
source

Source: https://habr.com/ru/post/1341253/


All Articles