Automatically exported from code.google.com/p/planningalerts
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

display.php 3.6 KiB

18 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * $Header: /home/ppcvs/paypal_php_sdk/Log/display.php,v 1.1 2006/02/19 08:22:29 dennis Exp $
  4. *
  5. * @version $Revision: 1.1 $
  6. * @package Log
  7. */
  8. /**
  9. * The Log_display class is a concrete implementation of the Log::
  10. * abstract class which writes message into browser in usual PHP maner.
  11. * This may be useful because when you use PEAR::setErrorHandling in
  12. * PEAR_ERROR_CALLBACK mode error messages are not displayed by
  13. * PHP error handler.
  14. *
  15. * @author Paul Yanchenko <pusher@inaco.ru>
  16. * @since Log 1.8.0
  17. * @package Log
  18. *
  19. * @example display.php Using the display handler.
  20. */
  21. class Log_display extends Log
  22. {
  23. /**
  24. * String to output before an error message
  25. * @var string
  26. * @access private
  27. */
  28. var $_error_prepend = '';
  29. /**
  30. * String to output after an error message
  31. * @var string
  32. * @access private
  33. */
  34. var $_error_append = '';
  35. /**
  36. * String used to represent a line break.
  37. * @var string
  38. * @access private
  39. */
  40. var $_linebreak = "<br />\n";
  41. /**
  42. * Constructs a new Log_display object.
  43. *
  44. * @param string $name Ignored.
  45. * @param string $ident The identity string.
  46. * @param array $conf The configuration array.
  47. * @param int $level Log messages up to and including this level.
  48. * @access public
  49. */
  50. function Log_display($name = '', $ident = '', $conf = array(),
  51. $level = PEAR_LOG_DEBUG)
  52. {
  53. $this->_id = md5(microtime());
  54. $this->_ident = $ident;
  55. $this->_mask = Log::UPTO($level);
  56. if (isset($conf['error_prepend'])) {
  57. $this->_error_prepend = $conf['error_prepend'];
  58. } else {
  59. $this->_error_prepend = ini_get('error_prepend_string');
  60. }
  61. if (isset($conf['error_append'])) {
  62. $this->_error_append = $conf['error_append'];
  63. } else {
  64. $this->_error_append = ini_get('error_append_string');
  65. }
  66. if (isset($conf['linebreak'])) {
  67. $this->_linebreak = $conf['linebreak'];
  68. }
  69. }
  70. /**
  71. * Writes $message to the text browser. Also, passes the message
  72. * along to any Log_observer instances that are observing this Log.
  73. *
  74. * @param mixed $message String or object containing the message to log.
  75. * @param string $priority The priority of the message. Valid
  76. * values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT,
  77. * PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING,
  78. * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG.
  79. * @return boolean True on success or false on failure.
  80. * @access public
  81. */
  82. function log($message, $priority = null)
  83. {
  84. /* If a priority hasn't been specified, use the default value. */
  85. if ($priority === null) {
  86. $priority = $this->_priority;
  87. }
  88. /* Abort early if the priority is above the maximum logging level. */
  89. if (!$this->_isMasked($priority)) {
  90. return false;
  91. }
  92. /* Extract the string representation of the message. */
  93. $message = $this->_extractMessage($message);
  94. /* Build and output the complete log line. */
  95. echo $this->_error_prepend .
  96. '<b>' . ucfirst($this->priorityToString($priority)) . '</b>: '.
  97. nl2br(htmlspecialchars($message)) .
  98. $this->_error_append . $this->_linebreak;
  99. /* Notify observers about this log message. */
  100. $this->_announce(array('priority' => $priority, 'message' => $message));
  101. return true;
  102. }
  103. }