zf2 – logger problems with the FirePhp/FireBug writer in a console request

Martin Zellerphp, zf2 Leave a Comment

In my  recent zf2 (zend framework 2.1) project module I defined a logger with a stream writer and a firephp writer. I am using the same module also for some console requests (Zend\Console). The problem I had was that the system complains of the firephp logger when I did a console request:

[plain]

======================================================================
The application has thrown an exception!
======================================================================
Exception
Headers already sent in C:\…\Zend\Console\Adapter\AbstractAdapter.php
on line 56. Cannot send log data to FirePHP. You must have Output Buffering
enabled via ob_start() or output_buffering ini directive.
———————————————————————-

[/plain]

Short: Cannot send log data to FirePHP. 

So I changed my local.php file to differentiate between a HTTP request and a console request.

This is the important part of the service_manager/factories configuration:

[php]

‘Zend\Log\Logger’ => function($sm) {
$request = $sm->get(‘Request’);
$logger = new \Zend\Log\Logger();
if ($request instanceof Zend\Console\Request) {
$file = new \Zend\Log\Writer\Stream(__DIR__ . ‘/../../data/dev-console.log’);
$logger->addWriter($file);
} else {
$writer_firebug = new \Zend\Log\Writer\FirePhp();
$writer_stream = new \Zend\Log\Writer\Stream(__DIR__ . ‘/../../data/dev.log’);
$logger->addWriter($writer_firebug);
$logger->addWriter($writer_stream);
}

return $logger;
}

[/php]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.