PageRenderTime 25ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/xampp/php/PEAR/Log/display.php

https://github.com/edmondscommerce/XAMPP-Magento-Demo-Site
PHP | 161 lines | 70 code | 17 blank | 74 comment | 12 complexity | 9544926ed9052689c8bc118c5f6317a5 MD5 | raw file
  1. <?php
  2. /**
  3. * $Header: /repository/pear/Log/Log/display.php,v 1.11 2008/03/20 16:03:57 jon Exp $
  4. *
  5. * @version $Revision: 1.11 $
  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 containing the format of a log line.
  25. * @var string
  26. * @access private
  27. */
  28. var $_lineFormat = '<b>%3$s</b>: %4$s';
  29. /**
  30. * String containing the timestamp format. It will be passed directly to
  31. * strftime(). Note that the timestamp string will generated using the
  32. * current locale.
  33. * @var string
  34. * @access private
  35. */
  36. var $_timeFormat = '%b %d %H:%M:%S';
  37. /**
  38. * Constructs a new Log_display object.
  39. *
  40. * @param string $name Ignored.
  41. * @param string $ident The identity string.
  42. * @param array $conf The configuration array.
  43. * @param int $level Log messages up to and including this level.
  44. * @access public
  45. */
  46. function Log_display($name = '', $ident = '', $conf = array(),
  47. $level = PEAR_LOG_DEBUG)
  48. {
  49. $this->_id = md5(microtime());
  50. $this->_ident = $ident;
  51. $this->_mask = Log::UPTO($level);
  52. /* Start by configuring the line format. */
  53. if (!empty($conf['lineFormat'])) {
  54. $this->_lineFormat = str_replace(array_keys($this->_formatMap),
  55. array_values($this->_formatMap),
  56. $conf['lineFormat']);
  57. }
  58. /* We may need to prepend a string to our line format. */
  59. $prepend = null;
  60. if (isset($conf['error_prepend'])) {
  61. $prepend = $conf['error_prepend'];
  62. } else {
  63. $prepend = ini_get('error_prepend_string');
  64. }
  65. if (!empty($prepend)) {
  66. $this->_lineFormat = $prepend . $this->_lineFormat;
  67. }
  68. /* We may also need to append a string to our line format. */
  69. $append = null;
  70. if (isset($conf['error_append'])) {
  71. $append = $conf['error_append'];
  72. } else {
  73. $append = ini_get('error_append_string');
  74. }
  75. if (!empty($append)) {
  76. $this->_lineFormat .= $append;
  77. }
  78. /* Lastly, the line ending sequence is also configurable. */
  79. if (isset($conf['linebreak'])) {
  80. $this->_lineFormat .= $conf['linebreak'];
  81. } else {
  82. $this->_lineFormat .= "<br />\n";
  83. }
  84. /* The user can also change the time format. */
  85. if (!empty($conf['timeFormat'])) {
  86. $this->_timeFormat = $conf['timeFormat'];
  87. }
  88. }
  89. /**
  90. * Opens the display handler.
  91. *
  92. * @access public
  93. * @since Log 1.9.6
  94. */
  95. function open()
  96. {
  97. $this->_opened = true;
  98. return true;
  99. }
  100. /**
  101. * Closes the display handler.
  102. *
  103. * @access public
  104. * @since Log 1.9.6
  105. */
  106. function close()
  107. {
  108. $this->_opened = false;
  109. return true;
  110. }
  111. /**
  112. * Writes $message to the text browser. Also, passes the message
  113. * along to any Log_observer instances that are observing this Log.
  114. *
  115. * @param mixed $message String or object containing the message to log.
  116. * @param string $priority The priority of the message. Valid
  117. * values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT,
  118. * PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING,
  119. * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG.
  120. * @return boolean True on success or false on failure.
  121. * @access public
  122. */
  123. function log($message, $priority = null)
  124. {
  125. /* If a priority hasn't been specified, use the default value. */
  126. if ($priority === null) {
  127. $priority = $this->_priority;
  128. }
  129. /* Abort early if the priority is above the maximum logging level. */
  130. if (!$this->_isMasked($priority)) {
  131. return false;
  132. }
  133. /* Extract the string representation of the message. */
  134. $message = $this->_extractMessage($message);
  135. /* Build and output the complete log line. */
  136. echo $this->_format($this->_lineFormat,
  137. strftime($this->_timeFormat),
  138. $priority,
  139. nl2br(htmlspecialchars($message)));
  140. /* Notify observers about this log message. */
  141. $this->_announce(array('priority' => $priority, 'message' => $message));
  142. return true;
  143. }
  144. }