What's more efficient - storing logs in sql database or files?

后端 未结 9 1500
暗喜
暗喜 2020-12-15 03:30

I have few scripts loaded by cron quite often. Right now I don\'t store any logs, so if any script fails to load, I won\'t know it till I see results - and even when I notic

9条回答
  •  伪装坚强ぢ
    2020-12-15 04:03

    You can use a component such as Zend_Log which natively supports the concept of writers attached to the same log instance. In that way you can log the same message to one or more different place with no need to change your logging code. And you can always change your code to replace the log system or add a new one in a simple way.

    For your question I think that log to files is simpler and more appropriate if you (developer) is the only one who needs to read log messages.

    Log to db instead if you need other people needs to read logs in a web interface or if you need the ability to search through logs. As someone else has pointed out also concurrency matters, if you have a lot of users log to db could scale better.

    Finally, a log frequency of 5 messages per minute requires almost no cpu for your application, so you don't need to worry about performances. In your case I'd start with logfiles and then change (or add more writers) if your requisites will change.

提交回复
热议问题