Zend_Log-Writers-Firebug.xml 7.1 KB

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