Logging custom elements Zend Log Formatter XML

Kethathigeoft

New Member
I'm trying to some information about a request and the result should be put in an XML file.I'm using the following elements:
  • logEntry(root) (default)
    • timestamp (default) (string) timestamp
    • priority (default) (string) priority
    • priorityName (default) (string) priority name
    • message (default) (string) message
    • uniqueId (new) (string) unique id
    • method (new) (string) Namespace\Class::MethodName()
    • args (new) (string) base64 encoded, serialized func_get_args();
Should be:\[code\]<logEntry><timestamp>2013-03-29T15:47:41+01:00</timestamp><priority>6</priority><priorityName>INFO</priorityName><message>Called</message><uniqueId>564fg56d4g5d4fg5f4g56fg465dfg</uniqueId><method>\Namespace\Controller::methodName</method><args>aa5abc8d6efeabcd7f67cb6a7df6bac5ba7a5fd7a5d6bac67a5bf6abcbb408f098=</args></logEntry>\[/code\]The documentation I've read:http://zf2.readthedocs.org/en/latest/modules/zend.log.formatters.htmlThe not-working code:\[code\]$writer = new \Zend\Log\Writer\Stream(getenv('LOG_FILE_LOCATION'));$formatter = new \Zend\Log\Formatter\Xml('logEntry', array( 'timestamp' => 'timestamp', 'priority' => 'priority', 'priorityName' => 'priorityName', 'message' => 'message', 'uniqueId' => 'uniqueId', 'method' => 'method', 'args' => 'args',));$writer->setFormatter($formatter);$logger = new \Zend\Log\Logger();$logger->addWriter($writer);$logger->info('Started', array( 'uniqueId' => $this->createGuid(), 'method' => __METHOD__, 'args' => serialize(array(get_class($e))), ));\[/code\]Error:Notice: Undefined index: uniqueId in /var/www/library/Zend/Log/Formatter/Xml.php on line 168 Code for Xml.phphttps://github.com/zendframework/zf2/blob/master/library/Zend/Log/Formatter/Xml.php#L168$event[$fieldKey] is the problem. $fieldKey only exists in $event['extra'][$fieldKey].$this->elementMap is flat(no extra array for extra is added).\[code\]Array( [timestamp] => timestamp [priority] => priority [priorityName] => priorityName [message] => message [uniqueId] => uniqueId [method] => method [args] => args)\[/code\]What am I doing wrong?I'm thinking this is a ZF2 bug... When reading the code on Github, I can't find and detectection for extra fields and keys... What do you guys think?
 
Back
Top