Is it better to save the log to the database or the local file?

this is true. If the mall wants to dock with third-party payment, now it needs to add a callback log in the payment callback entry, and all requests that have entered the callback are saved in the log. Now there is a question as to whether the callback log should be saved to the database or to a local file. saving to the database is afraid of taking up database resources. Callback requests now have millions of requests every day, and there is the possibility of concurrent requests. In the end, whether the callback log is written to the database or the local file. Ask for an experienced Daniel solution

Mar.30,2021

it is recommended to save to the log file. The log volume is large. Each time you save the database, you will increase the write burden of the database, and put it in the log file. Later, you can do similar Logstash applications to do log collection and data visualization analysis. At this time, you do not have to worry about the extra database reading burden. After all, the database read and write resources are very important.


this saves the database well and is not easy to delete.


I agree with the suggestion upstairs. It is not recommended to save to the database in the case of such concurrency and data volume. When the amount of data gradually takes up more and more disk space of the database, the performance of the database will be a new problem.

give two suggestions to the subject

  1. Save log data to local files, and store regular backups to other places
  2. how to involve log analysis in the future, you can consider third-party log services. For example, Aliyun's log service (definitely not advertising, because I am using it)
Menu