Zend_Log-Writers-ZendMonitor.xml 4.4 KB

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