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

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

Open
Martin-P opened this issue Mar 7, 2016 · 1 comment

Comments

@Martin-P
Copy link
Contributor

Martin-P commented Mar 7, 2016

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

SQL:

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`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

Module.php

<?php
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');
        $writer->setFormatter($formatter);

        $logger = new \Zend\Log\Logger();
        $logger->addWriter($writer);
        $logger->registerExceptionHandler($logger);

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

Original issue: zendframework/zendframework#2592

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants