1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
|
<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect2 id="zend.log.writers.firebug">
<title>Writing to Firebug</title>
<para>
<classname>Zend_Log_Writer_Firebug</classname> sends log
data to the <ulink url="http://www.getfirebug.com/">Firebug</ulink>
<ulink url="http://getfirebug.com/logging.html">Console</ulink>.
</para>
<para>
<inlinegraphic fileref="figures/zend.wildfire.firebug.console.png" format="PNG"
scale="100" width="310" />
</para>
<para>
All data is sent via the <classname>Zend_Wildfire_Channel_HttpHeaders</classname> component
which uses <acronym>HTTP</acronym> headers to ensure the page content is not disturbed.
Debugging <acronym>AJAX</acronym> requests that require clean <acronym>JSON</acronym> and
<acronym>XML</acronym> responses is possible with this approach.
</para>
<para>
Requirements:
</para>
<itemizedlist>
<listitem>
<para>
Firefox Browser ideally version 3 but version 2 is also supported.
</para>
</listitem>
<listitem>
<para>
Firebug Firefox Extension which you can download from <ulink
url="https://addons.mozilla.org/en-US/firefox/addon/1843">https://addons.mozilla.org/en-US/firefox/addon/1843</ulink>.
</para>
</listitem>
<listitem>
<para>
FirePHP Firefox Extension which you can download from <ulink
url="https://addons.mozilla.org/en-US/firefox/addon/6149">https://addons.mozilla.org/en-US/firefox/addon/6149</ulink>.
</para>
</listitem>
</itemizedlist>
<example id="zend.log.writers.firebug.example.with_front_controller">
<title>Logging with Zend_Controller_Front</title>
<programlisting language="php"><![CDATA[
// 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);
]]></programlisting>
</example>
<example id="zend.log.writers.firebug.example.without_front_controller">
<title>Logging without Zend_Controller_Front</title>
<programlisting language="php"><![CDATA[
$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();
]]></programlisting>
</example>
<sect3 id="zend.log.writers.firebug.priority-styles">
<title>Setting Styles for Priorities</title>
<para>
Built-in and user-defined priorities can be styled with the
<methodname>setPriorityStyle()</methodname> method.
</para>
<programlisting language="php"><![CDATA[
$logger->addPriority('FOO', 8);
$writer->setPriorityStyle(8, 'TRACE');
$logger->foo('Foo Message');
]]></programlisting>
<para>
The default style for user-defined priorities can be set with the
<methodname>setDefaultPriorityStyle()</methodname> method.
</para>
<programlisting language="php"><![CDATA[
$writer->setDefaultPriorityStyle('TRACE');
]]></programlisting>
<para>
The supported styles are as follows:
<table id="zend.log.writers.firebug.priority-styles.table">
<title>Firebug Logging Styles</title>
<tgroup cols="2">
<thead>
<row>
<entry>Style</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry><constant>LOG</constant></entry>
<entry>Displays a plain log message</entry>
</row>
<row>
<entry><constant>INFO</constant></entry>
<entry>Displays an info log message</entry>
</row>
<row>
<entry><constant>WARN</constant></entry>
<entry>Displays a warning log message</entry>
</row>
<row>
<entry><constant>ERROR</constant></entry>
<entry>
Displays an error log message that increments Firebug's error count
</entry>
</row>
<row>
<entry><constant>TRACE</constant></entry>
<entry>Displays a log message with an expandable stack trace</entry>
</row>
<row>
<entry><constant>EXCEPTION</constant></entry>
<entry>
Displays an error long message with an expandable stack trace
</entry>
</row>
<row>
<entry><constant>TABLE</constant></entry>
<entry>Displays a log message with an expandable table</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
</sect3>
<sect3 id="zend.log.writers.firebug.preparing-data">
<title>Preparing data for Logging</title>
<para>
While any <acronym>PHP</acronym> variable can be logged with the built-in priorities,
some special formatting is required if using some of the more specialized log styles.
</para>
<para>
The <constant>LOG</constant>, <constant>INFO</constant>, <constant>WARN</constant>,
<constant>ERROR</constant> and <constant>TRACE</constant> styles require no special
formatting.
</para>
</sect3>
<sect3 id="zend.log.writers.firebug.preparing-data.exception">
<title>Exception Logging</title>
<para>
To log a <classname>Zend_Exception</classname> 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.
</para>
<programlisting language="php"><![CDATA[
$exception = new Zend_Exception('Test exception');
$logger->err($exception);
]]></programlisting>
</sect3>
<sect3 id="zend.log.writers.firebug.preparing-data.table">
<title>Table Logging</title>
<para>
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.
</para>
<programlisting language="php"><![CDATA[
$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);
]]></programlisting>
</sect3>
</sect2>
|