[MANUAL] English:
[zend.git] / documentation / manual / en / module_specs / Zend_Log-Writers-Firebug.xml
blob556d5afb51942d05a97f36becc9f0e234acad819
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!-- Reviewed: no -->
3 <sect2 id="zend.log.writers.firebug">
4     <title>Writing to Firebug</title>
6     <para>
7         <classname>Zend_Log_Writer_Firebug</classname> sends log
8         data to the <ulink url="http://www.getfirebug.com/">Firebug</ulink>
9         <ulink url="http://getfirebug.com/logging.html">Console</ulink>.
10     </para>
12     <para>
13         <inlinegraphic fileref="figures/zend.wildfire.firebug.console.png" format="PNG"
14             scale="100" width="310" />
15     </para>
17     <para>
18         All data is sent via the <classname>Zend_Wildfire_Channel_HttpHeaders</classname> component
19         which uses <acronym>HTTP</acronym> headers to ensure the page content is not disturbed.
20         Debugging <acronym>AJAX</acronym> requests that require clean <acronym>JSON</acronym> and
21         <acronym>XML</acronym> responses is possible with this approach.
22     </para>
24     <para>
25         Requirements:
26     </para>
28     <itemizedlist>
29         <listitem>
30             <para>
31                 Firefox Browser ideally version 3 but version 2 is also supported.
32             </para>
33         </listitem>
35         <listitem>
36             <para>
37                 Firebug Firefox Extension which you can download from <ulink
38                     url="https://addons.mozilla.org/en-US/firefox/addon/1843">https://addons.mozilla.org/en-US/firefox/addon/1843</ulink>.
39             </para>
40         </listitem>
42         <listitem>
43             <para>
44                 FirePHP Firefox Extension which you can download from <ulink
45                     url="https://addons.mozilla.org/en-US/firefox/addon/6149">https://addons.mozilla.org/en-US/firefox/addon/6149</ulink>.
46             </para>
47         </listitem>
48     </itemizedlist>
50     <example id="zend.log.writers.firebug.example.with_front_controller">
51         <title>Logging with Zend_Controller_Front</title>
53         <programlisting language="php"><![CDATA[
54 // Place this in your bootstrap file before dispatching your front controller
55 $writer = new Zend_Log_Writer_Firebug();
56 $logger = new Zend_Log($writer);
58 // Use this in your model, view and controller files
59 $logger->log('This is a log message!', Zend_Log::INFO);
60 ]]></programlisting>
61     </example>
63     <example id="zend.log.writers.firebug.example.without_front_controller">
64         <title>Logging without Zend_Controller_Front</title>
66         <programlisting language="php"><![CDATA[
67 $writer = new Zend_Log_Writer_Firebug();
68 $logger = new Zend_Log($writer);
70 $request = new Zend_Controller_Request_Http();
71 $response = new Zend_Controller_Response_Http();
72 $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
73 $channel->setRequest($request);
74 $channel->setResponse($response);
76 // Start output buffering
77 ob_start();
79 // Now you can make calls to the logger
81 $logger->log('This is a log message!', Zend_Log::INFO);
83 // Flush log data to browser
84 $channel->flush();
85 $response->sendHeaders();
86 ]]></programlisting>
87     </example>
89     <sect3 id="zend.log.writers.firebug.priority-styles">
90         <title>Setting Styles for Priorities</title>
92         <para>
93             Built-in and user-defined priorities can be styled with the
94             <methodname>setPriorityStyle()</methodname> method.
95         </para>
97         <programlisting language="php"><![CDATA[
98 $logger->addPriority('FOO', 8);
99 $writer->setPriorityStyle(8, 'TRACE');
100 $logger->foo('Foo Message');
101 ]]></programlisting>
103         <para>
104             The default style for user-defined priorities can be set with the
105             <methodname>setDefaultPriorityStyle()</methodname> method.
106         </para>
108         <programlisting language="php"><![CDATA[
109 $writer->setDefaultPriorityStyle('TRACE');
110 ]]></programlisting>
112         <para>
113             The supported styles are as follows:
115             <table id="zend.log.writers.firebug.priority-styles.table">
116                 <title>Firebug Logging Styles</title>
118                 <tgroup cols="2">
119                     <thead>
120                         <row>
121                             <entry>Style</entry>
122                             <entry>Description</entry>
123                         </row>
124                     </thead>
126                     <tbody>
127                         <row>
128                             <entry><constant>LOG</constant></entry>
129                             <entry>Displays a plain log message</entry>
130                         </row>
132                         <row>
133                             <entry><constant>INFO</constant></entry>
134                             <entry>Displays an info log message</entry>
135                         </row>
137                         <row>
138                             <entry><constant>WARN</constant></entry>
139                             <entry>Displays a warning log message</entry>
140                         </row>
142                         <row>
143                             <entry><constant>ERROR</constant></entry>
145                             <entry>
146                                 Displays an error log message that increments Firebug's error count
147                             </entry>
148                         </row>
150                         <row>
151                             <entry><constant>TRACE</constant></entry>
152                             <entry>Displays a log message with an expandable stack trace</entry>
153                         </row>
155                         <row>
156                             <entry><constant>EXCEPTION</constant></entry>
157                             <entry>
158                                 Displays an error long message with an expandable stack trace
159                             </entry>
160                         </row>
162                         <row>
163                             <entry><constant>TABLE</constant></entry>
164                             <entry>Displays a log message with an expandable table</entry>
165                         </row>
166                     </tbody>
167                 </tgroup>
168             </table>
169         </para>
170     </sect3>
172     <sect3 id="zend.log.writers.firebug.preparing-data">
173         <title>Preparing data for Logging</title>
175         <para>
176             While any <acronym>PHP</acronym> variable can be logged with the built-in priorities,
177             some special formatting is required if using some of the more specialized log styles.
178         </para>
180         <para>
181             The <constant>LOG</constant>, <constant>INFO</constant>, <constant>WARN</constant>,
182             <constant>ERROR</constant> and <constant>TRACE</constant> styles require no special
183             formatting.
184         </para>
185     </sect3>
187     <sect3 id="zend.log.writers.firebug.preparing-data.exception">
188         <title>Exception Logging</title>
190         <para>
191             To log a <classname>Zend_Exception</classname> simply pass the exception object to the
192             logger. It does not matter which priority or style you have set as the exception is
193             automatically recognized.
194         </para>
196         <programlisting language="php"><![CDATA[
197 $exception = new Zend_Exception('Test exception');
198 $logger->err($exception);
199 ]]></programlisting>
200     </sect3>
202     <sect3 id="zend.log.writers.firebug.preparing-data.table">
203         <title>Table Logging</title>
205         <para>
206             You can also log data and format it in a table style. Columns are automatically
207             recognized and the first row of data automatically becomes the header.
208         </para>
210         <programlisting language="php"><![CDATA[
211 $writer->setPriorityStyle(8, 'TABLE');
212 $logger->addPriority('TABLE', 8);
214 $table = array('Summary line for the table',
215              array(
216                  array('Column 1', 'Column 2'),
217                  array('Row 1 c 1',' Row 1 c 2'),
218                  array('Row 2 c 1',' Row 2 c 2')
219              )
220             );
221 $logger->table($table);
222 ]]></programlisting>
223     </sect3>
224 </sect2>