phpzend-frameworkzend-dbzend-log

Where should I store custom php logs?


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?


Solution

  • 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.