Zend_Log-Writers-ZendMonitor.xml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect2 id="zend.log.writers.zendmonitor">
  4. <title>Writing to the Zend Server Monitor</title>
  5. <para>
  6. <classname>Zend_Log_Writer_ZendMonitor</classname> allows you to log events via Zend
  7. Server's Monitor API. This allows you to aggregate log messages for your entire application
  8. environment in a single location. Internally, it simply uses the
  9. <methodname>monitor_custom_event()</methodname> function from the Zend Monitor API.
  10. </para>
  11. <para>
  12. One particularly useful feature of the Monitor API is that it allows you to specify
  13. arbitrary custom information alongside the log message. For instance, if you wish to log an
  14. exception, you can log not just the exception message, but pass the entire exception object
  15. to the function, and then inspect the object within the Zend Server event monitor.
  16. </para>
  17. <note>
  18. <title>Zend Monitor must be installed and enabled</title>
  19. <para>
  20. In order to use this log writer, Zend Monitor must be both installed and enabled.
  21. However, it is designed such that if Zend Monitor is not detected, it will simply act as
  22. a <constant>NULL</constant> logger.
  23. </para>
  24. </note>
  25. <para>
  26. Instantiating the <classname>ZendMonitor</classname> log writer is trivial:
  27. </para>
  28. <programlisting language="php"><![CDATA[
  29. $writer = new Zend_Log_Writer_ZendMonitor();
  30. $log = new Zend_Log($writer);
  31. ]]></programlisting>
  32. <para>
  33. Then, simply log messages as usual:
  34. </para>
  35. <programlisting language="php"><![CDATA[
  36. $log->info('This is a message');
  37. ]]></programlisting>
  38. <para>
  39. If you want to specify additional information to log with the event, pass that information
  40. in a second parameter:
  41. </para>
  42. <programlisting language="php"><![CDATA[
  43. $log->info('Exception occurred', $e);
  44. ]]></programlisting>
  45. <para>
  46. The second parameter may be a scalar, object, or array; if you need to pass multiple pieces
  47. of information, the best way to do so is to pass an associative array.
  48. </para>
  49. <programlisting language="php"><![CDATA[
  50. $log->info('Exception occurred', array(
  51. 'request' => $request,
  52. 'exception' => $e,
  53. ));
  54. ]]></programlisting>
  55. <para>
  56. Within Zend Server, your event is logged as a "custom event". From the "Monitor" tab, select
  57. the "Events" sub-item, and then filter on "Custom" to see custom events.
  58. </para>
  59. <para>
  60. <inlinegraphic fileref="figures/zend.log.writers.zendmonitor-events.png" format="PNG" />
  61. </para>
  62. <para>
  63. Events in Zend Server's Monitor dashboard
  64. </para>
  65. <para>
  66. In this screenshot, the first two events listed are custom events logged via the
  67. <classname>ZendMonitor</classname> log writer. You may then click on an event to view all
  68. information related to it.
  69. </para>
  70. <para>
  71. <inlinegraphic fileref="figures/zend.log.writers.zendmonitor-event.png" format="PNG" />
  72. </para>
  73. <para>
  74. Event detail in Zend Server's Monitor
  75. </para>
  76. <para>
  77. Clicking on the "Custom" sub tab will detail any extra information you logged by passing the
  78. second argument to the logging method. This information will be logged as the
  79. <varname>info</varname> subkey; you can see that the request object was logged in this
  80. example.
  81. </para>
  82. <note>
  83. <title>Integration with Zend_Application</title>
  84. <para>
  85. By default, the <command>zf.sh</command> and <command>zf.bat</command> commands add
  86. configuration for the <link
  87. linkend="zend.application.available-resources.log"><classname>Zend_Application</classname>
  88. log resource</link>, which includes configuration for the
  89. <classname>ZendMonitor</classname> log writer. Additionally, the
  90. <classname>ErrorController</classname> uses the configured logger to log application
  91. exceptions -- providing you with Zend Monitor event integration by default.
  92. </para>
  93. <para>
  94. As noted previously, if the Monitor API is not detected in your <acronym>PHP</acronym>
  95. installation, the logger will simply act as a <constant>NULL</constant> logger.
  96. </para>
  97. </note>
  98. </sect2>