PageRenderTime 53ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/php/Log/display.php

https://bitbucket.org/adarshj/convenient_website
PHP | 108 lines | 40 code | 13 blank | 55 comment | 6 complexity | a9bda9bab5dd6b89c7273f2e3a459d8d MD5 | raw file
Possible License(s): Apache-2.0, MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-2-Clause, GPL-2.0, LGPL-3.0
  1. <?php
  2. /**
  3. * $Header: /repository/pear/Log/Log/display.php,v 1.6 2004/11/27 21:46:50 jon Exp $
  4. *
  5. * @version $Revision: 1.6 $
  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. * Constructs a new Log_display object.
  37. *
  38. * @param string $name Ignored.
  39. * @param string $ident The identity string.
  40. * @param array $conf The configuration array.
  41. * @param int $level Log messages up to and including this level.
  42. * @access public
  43. */
  44. function Log_display($name = '', $ident = '', $conf = array(),
  45. $level = PEAR_LOG_DEBUG)
  46. {
  47. $this->_id = md5(microtime());
  48. $this->_ident = $ident;
  49. $this->_mask = Log::UPTO($level);
  50. if (!empty($conf['error_prepend'])) {
  51. $this->_error_prepend = $conf['error_prepend'];
  52. } else {
  53. $this->_error_prepend = ini_get('error_prepend_string');
  54. }
  55. if (!empty($conf['error_append'])) {
  56. $this->_error_append = $conf['error_append'];
  57. } else {
  58. $this->_error_append = ini_get('error_append_string');
  59. }
  60. }
  61. /**
  62. * Writes $message to the text browser. Also, passes the message
  63. * along to any Log_observer instances that are observing this Log.
  64. *
  65. * @param mixed $message String or object containing the message to log.
  66. * @param string $priority The priority of the message. Valid
  67. * values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT,
  68. * PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING,
  69. * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG.
  70. * @return boolean True on success or false on failure.
  71. * @access public
  72. */
  73. function log($message, $priority = null)
  74. {
  75. /* If a priority hasn't been specified, use the default value. */
  76. if ($priority === null) {
  77. $priority = $this->_priority;
  78. }
  79. /* Abort early if the priority is above the maximum logging level. */
  80. if (!$this->_isMasked($priority)) {
  81. return false;
  82. }
  83. /* Extract the string representation of the message. */
  84. $message = $this->_extractMessage($message);
  85. /* Build and output the complete log line. */
  86. echo $this->_error_prepend .
  87. '<b>' . ucfirst($this->priorityToString($priority)) . '</b>: '.
  88. nl2br(htmlspecialchars($message)) .
  89. $this->_error_append . "<br />\n";
  90. /* Notify observers about this log message. */
  91. $this->_announce(array('priority' => $priority, 'message' => $message));
  92. return true;
  93. }
  94. }
  95. ?>