Undefined indexes and huge args-data in Zend\Log\Formatter\ExceptionHandler::format #2592

zfbot opened this Issue Sep 28, 2012 · 7 comments


None yet
6 participants

zfbot commented Sep 28, 2012

Jira Information

Original Issue:ZF2-566
Issue Type:Bug


In Zend\Log\Formatter\ExceptionHandler::format the assumtion is made that the indexes file, line, class and type always exist:

foreach ($event['extra']['trace'] as $trace) {
    $outputTrace .= "File  : {$trace['file']}\n"
                  . "Line  : {$trace['line']}\n"
                  . "Func  : {$trace['function']}\n"
                  . "Class : {$trace['class']}\n"
                  . "Type  : " . $this->getType($trace['type']) . "\n"
                  . "Args  : " . print_r($trace['args'], true) . "\n";
# The first trace does not contain the _file_ and _line_ indexes
# When the trace refers to a function (like call_user_func()), the indexes _class_ and _type_ do not exist
# print_r($trace['args'], true) creates a huge, huge string of data because all classes and their descendants are completely added as a string

I honestly think the logging (of exceptions) needs a serious rewrite, because there are just so many errors in it that it is unusable in this stage (also see [ZF2-562|http://framework.zend.com/issues/browse/ZF2-562] and [ZF2-563|http://framework.zend.com/issues/browse/ZF2-563]).

zfbot commented Sep 28, 2012

This issue was ported from the ZF2 Jira Issue Tracker at

Known GitHub users mentioned in the original message or comment:


Martin-P commented Mar 8, 2013

Please reopen this issue. It is still not working as it should and the undefined indexes and huge backtrace are still there. My initial report was not very descriptive and I can understand that it was hard to grasp. So here is a full testcase which illustrates the problem.

A warning in advance: this can seriously crash your browser as it tries to write over 20.000 lines of code to the browser screen!

The notices the script produces:

Notice: Undefined index: file in D:\websites_assets\Zend-2.1.4dev\library\Zend\Log\Formatter\ExceptionHandler.php on line 43

Notice: Undefined index: line in D:\websites_assets\Zend-2.1.4dev\library\Zend\Log\Formatter\ExceptionHandler.php on line 44


CREATE TABLE `_applicationlog` (
  `applicationlog_id` int(11) NOT NULL AUTO_INCREMENT,
  `log_date` datetime DEFAULT NULL,
  `message` text,
  `extra_file` varchar(300) DEFAULT NULL,
  `extra_line` varchar(10) DEFAULT NULL,
  `extra_trace` longtext,
  `priority` int(1) DEFAULT NULL,
  PRIMARY KEY (`applicationlog_id`)


namespace Log;

use Zend\Mvc\MvcEvent as MvcEvent;

class Module
     * On bootstrap event
     * @access public
     * @param MvcEvent $event
     * @return void
    public function onBootstrap(MvcEvent $event)
        $application = $event->getApplication();
        $sm = $application->getServiceManager();

        $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
        $mapping = array(
            'timestamp'   => 'log_date',
            'message'     => 'message',
            'extra'       => array(
                'file'  => 'extra_file',
                'line'  => 'extra_line',
                'trace' => 'extra_trace',
            'priority'    => 'priority',
        $writer = new \Zend\Log\Writer\Db($dbAdapter, '_applicationlog', $mapping);

        $formatter = new \Zend\Log\Formatter\ExceptionHandler();
        $formatter->setDateTimeFormat('Y-m-d H:i:s');

        $logger = new \Zend\Log\Logger();

        throw new \Exception('My custom message');

@weierophinney weierophinney reopened this Mar 8, 2013

@ghost ghost assigned ralphschindler Mar 12, 2013


ThaDafinser commented Nov 25, 2013

@Martin-P just tried your example and i run into a timeout...

The problem is on one hand the file/line/class/type does not exists, but the main problem (i run into a timeout) is L48

This is really huge!


weierophinney commented Feb 10, 2015

@Martin-P and/or @ThaDafinser Since you seem to have isolated the issue, any chance of a pull request with a fix? Also, it looks like the line @ThaDafinser references is not now what it was when that comment was written, so I'm not sure where the exact issue lies.


Martin-P commented Feb 10, 2015

When I look at the history of Zend\Log\Formatter\ExceptionHandler it is still the same line as @ThaDafinser mentioned: line 48. Litteraly everey created object is echo'd in a print_r which creates over 20.000 lines of text. The output should be limited to a few objects at most.

I will take a fresh look at this for a PR with fix.

GeeH commented Mar 5, 2016

This issues is being closed as part of the clean up of issues with the repository separation. If you feel this issues needs to be kept open then please create a new issue on the Zend\Log repository with a link to this issue.

@GeeH GeeH closed this Mar 5, 2016


Martin-P commented Mar 7, 2016

New issue created at zendframework/zend-log#32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment