Zend_Log-Writers-Firebug.xml 7.7 KB

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