ZF-8365: Zend_Log_Writer_Db fails on MySQL


Zend_Log_Writer_Db fails on MySQL due to an incorrect date format being used.

Zend_Log creates timestamps in an ISO-8601 format including the timezone, using date('c').

MySQL can not write this data to a datetime field:

Input: 2009-11-21T03:35:13+01:00 Output: Zend_Db_Exception with text: SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2009-11-21T03:56:33+01:00' for column 'timestamp' at row 1

Problem seems to be with the timezone; MySQL manual makes no mention of the timezone at all, and removing it from the input renders it valid to MySQL.

Current Zend_Log_Writer_Db is unusable with MySQL in its default state (no column mapping), so considering this a major issue.


use method Zend_Log:>setEventItem();

$log->setEventItem('timestamp', $date);

The proposed workaround-solution is not sufficient, as it sets the timestamp to a fixed value, instead of an up-to-date value for every log event being written.

Also, while I appreciate that it is possible to work around this problem, I believe the component should work properly, instead of having each and every programmer that wants to use it solve this issue themselves.

Because of this, I'm reopening the issue.

@Sander In ZF 1.10.0 was added to the parameter $ extras in Zend_Log::log().…

$log->info('Message', array('timestamp' => $date));
$log->log('Message', Zend_Log::INFO, array('timestamp' => $date));

Thanks Ramon! That's the workaround I initially used, but it breaks when other people had to work with the code as they didn't know about having to make this special exception just because we use Zend_Log_Writer_Db in combination with MySQL.

I am working on my own implementation of to help solve this issue, by having Zend_Log_Writer_Db pass a Zend_Date or PHP Date object to the log writer, and enabling the DB adapter to accept that, but it's not moving along very much.

With ZF-1.11.x was added Zend_Log::setTimestampFormat() or if you want working Zend_Date you can extend the class "Zend_Log" and override Zend_Log::_packEvent().