Writing to Firebug
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.
Logging with Zend_Controller_Front
log('This is a log message!', Zend_Log::INFO);
]]>
Logging without Zend_Controller_Front
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();
]]>
Setting Styles for Priorities
Built-in and user-defined priorities can be styled with the
setPriorityStyle() method.
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.
setDefaultPriorityStyle('TRACE');
]]>
The supported styles are as follows:
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
Preparing data for Logging
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.
Exception Logging
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.
err($exception);
]]>
Table Logging
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.
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);
]]>