Issues

ZF2-520: Logger exception handler generates a badly formatted log message

Issue Type: Bug Created: 2012-09-04T11:29:12.000+0000 Last Updated: 2012-10-08T20:14:42.000+0000 Status: Closed Fix version(s): Reporter: Yonni Mendes (yonman) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend\Log

  • ExceptionHandler
  • Logger

Related issues: Attachments:

Description

ZF2 RC7 Steps to reproduce: Initialize logging with writer and register the exception handler Logger::registerExceptionHandler Create a view script that throws an exception Dispatch the controller Note that request fails

Expected Log will hold a properly formatted exception message with readable trace, e.g.

<pre class="highlight">
ERR (3): exception 'Zend\Form\Exception\DomainException' with message 'Zend\Form\View\Helper\FormLabel::__invoke expects either label ..... Form/View/Helper/FormLabel.php:114
Stack trace:
#0 [internal function]: Zend\Form\View\Helper\FormLabel->__invoke(Object(Zend\Form\Element))
#1 /home/yonni/Zend/workspaces/DefaultWorkspace/ZendFramework-minimal-2.0.0rc7/library/Zend/View/Renderer/PhpRenderer.php(353): call_user_func_array(Object(Zend\Form\View\Helper\FormLabel), Array)
#2 /home/yonni/Zend/workspaces/DefaultWorkspace/gui.new/module/ZendServer/src/ZendServer/View/Helper/Form/Renderer/Table.php(36): Zend\View\Renderer\PhpRenderer->__call('FormLabel', Array)

Actual Log holds a json_encoded trace which is very difficult to decipher and seems to have gone through multiple character escaping. The entry is one long string, I broke it apart for easier reading

<pre class="highlight">
Zend\Form\View\Helper\FormLabel::__invoke expects ..... neither found {"file":"\/home\/yonni\/Zend\/workspaces\/DefaultWorkspace\/ZendFramework-minimal-2.0.0rc7\/library\/Zend\/Form\/View\/Helper\/FormLabel.php","line":114,"trace":"[\"
{\\\"function\\\":\\\"__invoke\\\",\\\"class\\\":\\\"Zend\\\\\\\\Form\\\\\\\\View\\\\\\\\Helper\\\\\\\\FormLabel\\\",\\\"type\\\":\\\"->\\\",\\\"args\\\":\\\"
[\\\\\\\"object(Zend\\\\\\\\\\\\\\\\Form\\\\\\\\\\\\\\\\Element) {}\\\\\\\"]\\\"}\",
\"{\\\"file\\\":\\\"\\\\\\\/home\\\\\\\/yonni\\\\\\\/Zend\\\\\\\/workspaces\\\\\\\/DefaultWorkspace\\\\\\\/ZendFramework-minimal-2.0.0rc7\\\\\\\/library\\\\\\\/Zend\\\\\\\/View\\\\\\\/Renderer\\\\\\\/PhpRenderer.php\\\",\\\"line\\\":353,\\\"function\\\":\\\"call_user_func_array\\\",\\\"args\\\":
\\\"[\\\\\\\"object(Zend\\\\\\\\\\\\\\\\Form\\\\\\\\\\\\\\\\View\\\\\\\\\\\\\\\\Helper\\\\\\\\\\\\\\\\FormLabel) {}\\\\\\\",
\\\\\\\"[\\\\\\\\\\\\\\\"object(Zend\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\Form\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\Element) {}\\\\\\\\\\\\\\\"]\\\\\\\"]\\\"}\",
\"{\\\"file\\\":\\\"\\\\\\\/home\\\\\\\/yonni\\\\\\\/Zend\\\\\\\/workspaces\\\\\\\/DefaultWorkspace\\\\\\\/gui.new\\\\\\\/module\\\\\\\/ZendServer\\\\\\\/src\\\\\\\/ZendServer\\\\\\\/View\\\\\\\/Helper\\\\\\\/Form\\\\\\\/Renderer\\\\\\\/Table.php\\\",\\\"line\\\":36,\\\"function\\\":\\\"__call\\\",\\\"class\\\":\\\"Zend\\\\\\\\View\\\\\\\\Renderer\\\\\\\\PhpRenderer\\\",\\\"type\\\":\\\"->\\\",\\\"args\\\":\\\"[\\\\\\\"FormLabel\\\\\\\",\\\\\\\"[\\\\\\\\\\\\\\\"object(Zend\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\Form\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\Element) {}\\\\\\\\\\\\\\\"]\\\\\\\"]\\\"}\",\"{\\\"file\\\":\\\"\\\\\\\/home\\\\\\\/yonni
.....

To resolve this locally I changed the following line (Zend\Log\Logger.php:437)

<pre class="highlight">
$logger->log(Logger::ERR, $exception->getMessage(), $extra);

To

<pre class="highlight">
$logger->log(Logger::ERR, $exception);

Effectively forcing the logger to use its own internal normalization and formatter

Comments

Posted by BenoƮt Durand (intiilapa) on 2012-09-11T19:12:53.000+0000

You can define your own exception handler. I don't think that we use the toString render of an exception, but improve the exception formatter.

I hope that you have extended your zf2 version instead of change the file. Do you know it's bad (practice)?

Too many slashes :)

Posted by Yonni Mendes (yonman) on 2012-09-12T06:51:44.000+0000

Naturally, extended outside the framework. Just to be sure this is clear - the same thing happens when any sort of extras array is passed, not only exceptions

Posted by Ralph Schindler (ralph) on 2012-10-08T20:14:42.000+0000

This issue has been closed on Jira and moved to GitHub for issue tracking. To continue following the resolution of this issues, please visit: https://github.com/zendframework/zf2/issues/2555

Have you found an issue?

See the Overview section for more details.

Copyright

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

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

Contacts