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.

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

报告相同问题?

悬赏问题

  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码