LoggerFilter.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * log4php is a PHP port of the log4j java logging package.
  4. *
  5. * <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
  6. * <p>Design, strategies and part of the methods documentation are developed by log4j team
  7. * (Ceki Gülcü as log4j project founder and
  8. * {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
  9. *
  10. * <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
  11. * For more information, please see {@link http://www.vxr.it/log4php/}.</p>
  12. *
  13. * <p>This software is published under the terms of the LGPL License
  14. * a copy of which has been included with this distribution in the LICENSE file.</p>
  15. *
  16. * @package log4php
  17. * @subpackage spi
  18. */
  19. /**
  20. * @ignore
  21. */
  22. if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  23. /**
  24. * The log event must be logged immediately without consulting with
  25. * the remaining filters, if any, in the chain.
  26. */
  27. define('LOG4PHP_LOGGER_FILTER_ACCEPT', 1);
  28. /**
  29. * This filter is neutral with respect to the log event. The
  30. * remaining filters, if any, should be consulted for a final decision.
  31. */
  32. define('LOG4PHP_LOGGER_FILTER_NEUTRAL', 0);
  33. /**
  34. * The log event must be dropped immediately without consulting
  35. * with the remaining filters, if any, in the chain.
  36. */
  37. define('LOG4PHP_LOGGER_FILTER_DENY', -1);
  38. /**
  39. * Users should extend this class to implement customized logging
  40. * event filtering. Note that {@link LoggerCategory} and {@link LoggerAppenderSkeleton},
  41. * the parent class of all standard
  42. * appenders, have built-in filtering rules. It is suggested that you
  43. * first use and understand the built-in rules before rushing to write
  44. * your own custom filters.
  45. *
  46. * <p>This abstract class assumes and also imposes that filters be
  47. * organized in a linear chain. The {@link #decide
  48. * decide(LoggerLoggingEvent)} method of each filter is called sequentially,
  49. * in the order of their addition to the chain.
  50. *
  51. * <p>The {@link decide()} method must return one
  52. * of the integer constants {@link LOG4PHP_LOG4PHP_LOGGER_FILTER_DENY},
  53. * {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} or {@link LOG4PHP_LOGGER_FILTER_ACCEPT}.
  54. *
  55. * <p>If the value {@link LOG4PHP_LOGGER_FILTER_DENY} is returned, then the log event is
  56. * dropped immediately without consulting with the remaining
  57. * filters.
  58. *
  59. * <p>If the value {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} is returned, then the next filter
  60. * in the chain is consulted. If there are no more filters in the
  61. * chain, then the log event is logged. Thus, in the presence of no
  62. * filters, the default behaviour is to log all logging events.
  63. *
  64. * <p>If the value {@link LOG4PHP_LOGGER_FILTER_ACCEPT} is returned, then the log
  65. * event is logged without consulting the remaining filters.
  66. *
  67. * <p>The philosophy of log4php filters is largely inspired from the
  68. * Linux ipchains.
  69. *
  70. * @author VxR <vxr@vxr.it>
  71. * @version $Revision: 1.1 $
  72. * @package log4php
  73. * @subpackage spi
  74. */
  75. class LoggerFilter {
  76. /**
  77. * @var LoggerFilter Points to the next {@link LoggerFilter} in the filter chain.
  78. */
  79. var $next;
  80. /**
  81. * Usually filters options become active when set. We provide a
  82. * default do-nothing implementation for convenience.
  83. */
  84. function activateOptions()
  85. {
  86. return;
  87. }
  88. /**
  89. * Decide what to do.
  90. * <p>If the decision is {@link LOG4PHP_LOGGER_FILTER_DENY}, then the event will be
  91. * dropped. If the decision is {@link LOG4PHP_LOGGER_FILTER_NEUTRAL}, then the next
  92. * filter, if any, will be invoked. If the decision is {@link LOG4PHP_LOGGER_FILTER_ACCEPT} then
  93. * the event will be logged without consulting with other filters in
  94. * the chain.
  95. *
  96. * @param LoggerLoggingEvent $event The {@link LoggerLoggingEvent} to decide upon.
  97. * @return integer {@link LOG4PHP_LOGGER_FILTER_NEUTRAL} or {@link LOG4PHP_LOGGER_FILTER_DENY}|{@link LOG4PHP_LOGGER_FILTER_ACCEPT}
  98. */
  99. function decide($event)
  100. {
  101. return LOG4PHP_LOGGER_FILTER_NEUTRAL;
  102. }
  103. }
  104. ?>