Zend_Log_Writer_Firebug sends log
data to the Firebug
Console.
All data is sent via the Zend_Wildfire_Channel_HttpHeaders component
which uses HTTP headers to ensure the page content is not disturbed.
Debugging AJAX requests that require clean JSON and
XML responses is possible with this approach.
Requirements:
Firefox Browser ideally version 3 but version 2 is also supported.
Firebug Firefox Extension which you can download from https://addons.mozilla.org/en-US/firefox/addon/1843.
FirePHP Firefox Extension which you can download from https://addons.mozilla.org/en-US/firefox/addon/6149.
Example 571. Logging with Zend_Controller_Front
<?php
// Place this in your bootstrap file before dispatching your front controller
$writer = new Zend_Log_Writer_Firebug();
$logger = new Zend_Log($writer);
// Use this in your model, view and controller files
$logger->log('This is a log message!', Zend_Log::INFO);
Example 572. Logging without Zend_Controller_Front
<?php
$writer = new Zend_Log_Writer_Firebug();
$logger = new Zend_Log($writer);
$request = new Zend_Controller_Request_Http();
$response = new Zend_Controller_Response_Http();
$channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
$channel->setRequest($request);
$channel->setResponse($response);
// Start output buffering
ob_start();
// Now you can make calls to the logger
$logger->log('This is a log message!', Zend_Log::INFO);
// Flush log data to browser
$channel->flush();
$response->sendHeaders();
Built-in and user-defined priorities can be styled with the
setPriorityStyle() method.
<?php
$logger->addPriority('FOO', 8);
$writer->setPriorityStyle(8, 'TRACE');
$logger->foo('Foo Message');
The default style for user-defined priorities can be set with the
setDefaultPriorityStyle() method.
<?php
$writer->setDefaultPriorityStyle('TRACE');
The supported styles are as follows:
Table 114. Firebug Logging Styles
| Style | Description |
|---|---|
LOG |
Displays a plain log message |
INFO |
Displays an info log message |
WARN |
Displays a warning log message |
ERROR |
Displays an error log message that increments Firebug's error count |
TRACE |
Displays a log message with an expandable stack trace |
EXCEPTION |
Displays an error long message with an expandable stack trace |
TABLE |
Displays a log message with an expandable table |
While any PHP variable can be logged with the built-in priorities, some special formatting is required if using some of the more specialized log styles.
The LOG, INFO, WARN,
ERROR and TRACE styles require no special
formatting.
To log a Zend_Exception simply pass the exception object to the
logger. It does not matter which priority or style you have set as the exception is
automatically recognized.
<?php
$exception = new Zend_Exception('Test exception');
$logger->err($exception);
You can also log data and format it in a table style. Columns are automatically recognized and the first row of data automatically becomes the header.
<?php
$writer->setPriorityStyle(8, 'TABLE');
$logger->addPriority('TABLE', 8);
$table = array('Summary line for the table',
array(
array('Column 1', 'Column 2'),
array('Row 1 c 1',' Row 1 c 2'),
array('Row 2 c 1',' Row 2 c 2')
)
);
$logger->table($table);




