Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Zend\Log\Formatter\Xml improvement to handle extra data array #6137

Closed
wants to merge 5 commits into from
Closed

Zend\Log\Formatter\Xml improvement to handle extra data array #6137

wants to merge 5 commits into from

Conversation

dkemper
Copy link
Contributor

@dkemper dkemper commented Apr 14, 2014

I found out, that the \Zend\Log\Formatter\Xml doesn´t support "extra" information, when its a extra data is an array. I made an example to show my little change.

Hope its useful.

Example-Code:

$stream = new \Zend\Log\Writer\Stream('data/log/application.log');
$stream->setFormatter(new \Zend\Log\Formatter\Xml());
$logger = new \Zend\Log\Logger();
$logger->addProcessor(new \Zend\Log\Processor\Backtrace());
$logger->addWriter($stream);

$logger->info('wrong stuff');

before:

<logEntry>
   <timestamp>2014-04-14T23:40:17+02:00</timestamp>
   <priority>6</priority>
   <priorityName>INFO</priorityName>
   <message>wrong stuff</message>
</logEntry>

after:

<logEntry>
  <timestamp>2014-04-14T23:40:17+02:00</timestamp>
  <priority>6</priority>
  <priorityName>INFO</priorityName>
  <message>wrong stuff</message>
  <extra>
      <file>/home/project/module/App/src/App/Controller/ConsoleController.php</file>        <line>51</line>
      <class>App\Controller\ConsoleController</class>
      <function>loggerTestAction</function>
  </extra>
</logEntry>

@weierophinney
Copy link
Member

What about nested arrays? If it's going to support arrays, may as well go the whole way! (hint: use recursion)

@dkemper
Copy link
Contributor Author

dkemper commented Apr 15, 2014

I made a initial version for nested array handling. I didn't find anything in the library. So i hope this version is a least something we can discuss about. Nameing etc.

$xml = preg_replace('/<\?xml version="1.0"( encoding="[^\"]*")?\?>\n/u', '', $xml);

return $xml . PHP_EOL;
}

/**
* Recursion function to crete a xml tree structure out of array structure
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an xml, not a xml

@ezimuel
Copy link
Contributor

ezimuel commented Apr 17, 2014

@dkemper can you provide a unit tests for a simple scenario (single array) and nested arrays?

@Ocramius Ocramius added this to the 2.4.0 milestone Jul 27, 2014
@Ocramius Ocramius self-assigned this Jul 27, 2014
Ocramius added a commit that referenced this pull request Jul 27, 2014
Ocramius added a commit that referenced this pull request Jul 27, 2014
Ocramius added a commit that referenced this pull request Jul 27, 2014
Ocramius added a commit that referenced this pull request Jul 27, 2014
Ocramius added a commit that referenced this pull request Jul 27, 2014
Ocramius added a commit that referenced this pull request Jul 27, 2014
@Ocramius
Copy link
Member

@dkemper manually merged @bf2d0d3308863185a1f70b8df8c3a9fddf06c5d8, thanks!

@Ocramius Ocramius closed this Jul 27, 2014
freax pushed a commit to freax/zf2 that referenced this pull request Nov 27, 2014
freax pushed a commit to freax/zf2 that referenced this pull request Nov 27, 2014
freax pushed a commit to freax/zf2 that referenced this pull request Nov 27, 2014
freax pushed a commit to freax/zf2 that referenced this pull request Nov 27, 2014
freax pushed a commit to freax/zf2 that referenced this pull request Nov 27, 2014
freax pushed a commit to freax/zf2 that referenced this pull request Nov 27, 2014
gianarb pushed a commit to zendframework/zend-log that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-log that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-log that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-log that referenced this pull request May 15, 2015
…nerated XML, avoiding writing it to a variable
gianarb pushed a commit to zendframework/zend-log that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-log that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-log that referenced this pull request May 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants