ZF-2658: More Flexible Mapping For Zend_Log_Writer_Db

Issue Type: Improvement Created: 2008-02-14T15:17:21.000+0000 Last Updated: 2011-03-26T17:22:07.000+0000 Status: Postponed Fix version(s): Reporter: Arthur Kang (arthurkang) Assignee: Eddo Rotman (karnaf) Tags: - Zend_Log

Related issues: Attachments:


In my opinion, the mapping logic is too rigid. If there is a mapping present, the insertion of log messages includes those fields and only those fields each and every time. This produces undesired results when:

New fields are added using the setEventItem method and there is no mapping for them. These fields will never be inserted.

When fields are empty and must be inserted as NULL, insertion failure. Since the fields are all named, these should just be skipped.

Fields that don't need to be mapped still must have a mapping entry, just so it is included ('message' => 'message').

I think most people would use mapping as an overload of field names. That would address all the issues above. Fields that are not overloaded (name wise) would be inserted as is. Something like the following:

Database ( creation, priority, message );

Mapping = array('creation' => 'timestamp');

<pre class="highlight">
if ($this->_columnMap === null) {
    $dataToInsert = $event;
} else {
    $dataToInsert = array();
    foreach ($this->_columnMap as $columnName => $fieldKey) {
        if (isset($event[$fieldKey])) { $dataToInsert[$columnName] = $event[$fieldKey]; }
    if (count($event)) {
        foreach ($event as $eventKey => $eventVal) {
            $dataToInsert[$eventKey] = $eventVal;

One final thought. In my opinion, the mapping logic should be reversed. So, instead of mapping database field names to log event items, it should be log event items mapped to database fields. Its not really a big deal, because you can just flip the mapping array, but I think it is more intuitive.


Posted by Wil Sinclair (wil) on 2009-01-26T09:36:17.000+0000

This seems like a worthy change. Arthur, have you signed a CLA so that we can use the code above? Also, can you write the necessary unit tests and add the necessary tables to the test schema?

Posted by Arthur Kang (arthurkang3) on 2009-01-27T12:16:40.000+0000

I have not signed a CLA. I will get that in.

I have no experience with unit tests.

Posted by Thomas Weidner (thomas) on 2010-03-21T10:26:58.000+0000

Reassigned to component maintainer

Posted by BenoƮt Durand (intiilapa) on 2011-03-26T17:22:07.000+0000

@Arthur, You have not yet signed the CLA apparently.

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.