duanchao1002 2012-05-02 13:19
浏览 44
已采纳

我应该在哪里存储自定义的PHP日志?

We have some custom logs that we maintain in the database (mysql). We use these logs to keep track of recent errors and email activity in our zend framework application.

We found out recently that these logs create some stress on the database, as we perform multiple read / writes on these log tabs. It's also slows down the application, as we need to perform mysql INSERTs, and sometimes these log tables get locked by other SELECT queries.

We use Zend_Log adapters to perform the log writes, as such:

    $columnMapping = array('url' => 'url', 'userAgent' => 'userAgent', 'info' => 'info', 'reffer' => 'reffer', 'userId' => 'userId', 'priority' => 'priority','dateInserted' => 'dateInserted', 'message' => 'message');
    $writer_db = new Zend_Log_Writer_Db($db, 'log', $columnMapping);

We also have a custom cronjob that cleans out old entries from the log each night, which also creates some stress on the database.

The only requirement we have for these logs, is that they should be searchable from a central location, as we have multiple servers writing these logs.

Any alternative for writing logs in a zend framework application? any good Zend_Log adapters that can help in this case?

  • 写回答

1条回答 默认 最新

  • dougengqiu8031 2012-05-02 13:26
    关注

    You could use a file logger to a "drive" that is shared among all the servers via NTP. It is searchable with the standard unix search tools (grep, awk, etc).

    Another solution would be to use the Syslog writer and set up a syslog server that receives the log messages. There are many applications that can analyze the syslog format.

    The third option would be to use MongoDB as a storage facility for your logs. Here is an article that explains how to implement a Log Writer that writes to MongoDB. MongoDB has "asynchronous inserts" so your application does not have to wait until the log entry was written to the database.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路