Issues

ZF2-18: Extending Zend_Log using namespaces

Description

In Zend_Log::factory in line 139 (ZF 1.11) an instance of Zend_Log is created with $log = new self;.

Let me give a use-case to explain:

somewhere at bootstrapping:


$autoloader = Zend_Loader_Autloader::getInstance();
$autoloader->registerNamespace("My_");
$autoloader->setFallbackAutoloader(true);

extending Zend_Log:


My_Log extends Zend_Log {

 public function log($message, $priority, $extras = null) {
     // do something else
     parent::log($message, $priority, $extras);
 }

}

Also at bootstrapping:


$logger = My_Log::factory(...);

So the My_Log::log method never will be called -> $log = new self;

First option is to override the Zend_Log::factory and replace $log = new self to $log = new My_Log, but this is urgh. Better code this:


$log = new static;

With this pice of code it is possible to get, due to late static binding, a instance of My_Log, and not Zend_Log...

What do u think?

Tested with ZF 1.8 - 1.11 - works fine (of course > PHP5.3)

cheers

Comments

@Eric ZF1 must be compatible with PHP 5.2.

I'm going to move this issue to the ZF2 issue tracker, as LSB is only available in PHP >= 5.3, and ZF1's minimum version is 5.2.6. There may be other ways to potentially support this in 5.2, but the proper way is using LSB.

All factory methods of logger, writers, filtesr, and formatters are being refactored within ZF2.

Okay, i dont respect the compatibility. So thanks for regarding this issue.

Once the common API (puggable, configurator, etc.) will have been decided for the core components of ZF2, Logger will adopt it. Being able to extend any core component is a requirement for this solution.

It is also possible to consider including events in order to customize the logging.

I see no reason for us to wait until after we refactor for the new configuration style to make this change. LSB is the correct way to handle a situation like this, and it's a simple enough change. I went ahead and issued a PR for this: https://github.com/zendframework/zf2/pull/680

Merged to master