laminas / laminas-log

Robust, composite logger with filtering, formatting, and PSR-3 support
https://docs.laminas.dev/laminas-log/
BSD 3-Clause "New" or "Revised" License
26 stars 30 forks source link

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

Closed weierophinney closed 3 years ago

weierophinney commented 4 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


Originally posted by @Martin-P at https://github.com/zendframework/zend-log/issues/32

weierophinney commented 3 years ago

This package is considered feature-complete, and is now in security-only maintenance mode, following a decision by the Technical Steering Committee. If you have a security issue, please follow our security reporting guidelines. If you wish to take on the role of maintainer, please nominate yourself

If you are looking for an actively maintained package alternative, we recommend: