ZF-8365: Zend_Log_Writer_Db fails on MySQL

Issue Type: Improvement Created: 2009-11-20T19:09:55.000+0000 Last Updated: 2011-01-09T18:22:31.000+0000 Status: Resolved Fix version(s): - 1.11.0 (02/Nov/10)

Reporter: Sander Bol (tubularbell) Assignee: Ramon Henrique Ornelas (ramon) Tags: - Zend_Log

Related issues: Attachments:


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.


Posted by Ramon Henrique Ornelas (ramon) on 2010-03-26T20:37:31.000+0000

use method Zend_Log:>setEventItem();

<pre class="highlight">
$log->setEventItem('timestamp', $date);

Posted by Sander Bol (tubularbell) on 2010-03-27T00:53:23.000+0000

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.

Posted by Ramon Henrique Ornelas (ramon) on 2010-03-27T04:37:09.000+0000

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

<pre class="highlight">
$log->info('Message', array('timestamp' => $date));
$log->log('Message', Zend_Log::INFO, array('timestamp' => $date));

Posted by Sander Bol (tubularbell) on 2010-03-27T08:13:00.000+0000

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.

Posted by Ramon Henrique Ornelas (ramon) on 2011-01-09T18:22:31.000+0000

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().

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.