We're using the Zend_Log class to update a few different "watchdog" database tables (that log different events: Batch scripts running, new data being processed, files generated, etc.).
Here is my current code (before the issue I'm looking into fixing.)
$writer = new Zend_Log_Writer_Db($db, 'watchdog', array(
'priority' => 'priority',
'message' => 'message',
'owner' => 'owner',
));
$logger = new Zend_Log($writer);
$logger->setEventItem('owner', 'MODULE_NAME');
This works perfectly fine. But, I want to add a database column called datetime that is a call to time()
at the time of the event. So, in theory, it would be something like this:
$writer = new Zend_Log_Writer_Db($db, 'watchdog', array(
'priority' => 'priority',
'message' => 'message',
'owner' => 'owner',
'datetime' => 'datetime',
));
$logger = new Zend_Log($writer);
$logger->setEventItem('owner', 'MODULE_NAME');
$logger->setEventItem('datetime', time());
The problem I'm running into is that, obviously, the call to time() runs at the first time Zend_Log::setEventItem
is called and not when Zend_Log::info()
is called. So, the question is, how do I get the time()
to be called and stored in my DB when Zend_Log::info()
is called? Will I need to extend Zend_Log_Writer_Db
with a more custom class?