Issues

ZF-32: Zend Log throwing an error without a default logger (TRAC#16)

Issue Type: Improvement Created: 2006-06-19T22:59:00.000+0000 Last Updated: 2007-07-05T14:43:07.000+0000 Status: Resolved Fix version(s): - 0.2.0 (29/Oct/06)

Reporter: Zend Framework (zend_framework) Assignee: Richard Thomas (cyberlot) Tags: - Zend_Log

Related issues: Attachments: - ZF-32.patch

Description

http://framework.zend.com/developer/ticket/16

Zend Log throws an error if you register all log adapters with a name (or without a default name to be exact).

Copy and paste from the manual - section 9.4:

<pre class="highlight">
require_once 'Zend/Log.php';                 // Zend_Log base class
require_once 'Zend/Log/Adapter/File.php';    // File log adapter
require_once 'Zend/Log/Adapter/Console.php'; // Console log adapter

Zend_Log::registerLogger(new Zend_Log_Adapter_File('framework.txt'), 'File');
Zend_Log::registerLogger(new Zend_Log_Adapter_Console(), 'Console');

Zend_Log::log('First logging message.');

Results in:

Fatal error: Uncaught exception 'Zend_Log_Exception' with message 'No instance of log named "LOG".' in /home/martel/WWW/ZendFramework/library/Zend/Log.php:151

It think it would be far better to register the first log adapter as a default one instead of using hard-wired default named "LOG".

Comments

Posted by Keith Pope (mute) on 2006-07-28T19:36:53.000+0000

I have added a simple patch for this issue.

All I have done is make the first logger registered the default logger.

The manual code should now work.

<pre class="highlight">
/**
     * Instantiates a new instance of Zend_Log carrying the supplied Zend_Log_Adapter_Interface and stores
     * it in the $_instances array.
     *
     * @param  Zend_Log_Adapter_Interface $logAdapter Log adapter implemented from Zend_Log_Adapter_Interface
     * @param  string                     $logName    Name of this instance, used to access it from other static functions.
     * @throws Zend_Log_Exception
     * @return boolean                    True
     */
    public static function registerLogger(Zend_Log_Adapter_Interface $logAdapter, $logName=null)
    {
        if (is_null($logName)) {
            $logName = self::$_defaultLogName;
        }

        /* @var $log Zend_Log */
        if (!self::hasLogger($logName)) {
            self::$_instances[$logName] = new Zend_Log($logName, $logAdapter);
        } else {
            throw new Zend_Log_Exception("Cannot register, \"$logName\" already exists.");
        }

        //make sure we have a default logger
        if(sizeof(self::$_instances == 1)) {
            self::setDefaultLogger($logName);
        }

        return true;
    }

Posted by Richard Thomas (cyberlot) on 2006-09-22T19:38:00.000+0000

The attached patch is invalid.

This is more a doc issue then anything else, even if the patch worked it assumes the user isn't using the default method and cause confusion.

If a developer is going to setup 2 distinct loggers they need to decide which one to use by default.

Posted by Richard Thomas (cyberlot) on 2006-09-22T19:38:59.000+0000

More a doc/use issue then anything else, suggested fix would break backwards compat without providing any real benifit.

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