zendframework / zend-log

Log component from Zend Framework
BSD 3-Clause "New" or "Revised" License
62 stars 51 forks source link

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

Open Martin-P opened 8 years ago

Martin-P commented 8 years ago

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: https://github.com/zendframework/zf2/issues/2592

weierophinney commented 4 years ago

This repository has been closed and moved to laminas/laminas-log; a new issue has been opened at https://github.com/laminas/laminas-log/issues/6.