Annotation of /com_supacart/trunk/admin_files/classes/Log/display.php
Parent Directory
|
Revision Log
Revision 4 - (view) (download)
| 1 : | andphe | 4 | <?php |
| 2 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 3 : | /** | ||
| 4 : | * | ||
| 5 : | * @version $Id: display.php 617 2007-01-04 19:43:08Z soeren_nb $ | ||
| 6 : | * @package SupaCart | ||
| 7 : | * @subpackage Log | ||
| 8 : | * See COPYRIGHT.php for copyright notices and details. | ||
| 9 : | * @license GNU/GPL Version 2, see LICENSE.php | ||
| 10 : | * SupaCart is free software, originally derived from Virtuemart. This version may have been modified pursuant | ||
| 11 : | * to the GNU General Public License, and as distributed it includes or | ||
| 12 : | * is derivative of works licensed under the GNU General Public License or | ||
| 13 : | * other free or open source software licenses. | ||
| 14 : | * See /administrator/components/com_supacart/COPYRIGHT.php for copyright notices and details. | ||
| 15 : | * | ||
| 16 : | * http://www.supacart.com | ||
| 17 : | */ | ||
| 18 : | |||
| 19 : | /** | ||
| 20 : | * $Header$ | ||
| 21 : | * | ||
| 22 : | * @version $ Revision: 1.8 $ | ||
| 23 : | * @package Log | ||
| 24 : | */ | ||
| 25 : | |||
| 26 : | /** | ||
| 27 : | * The Log_display class is a concrete implementation of the Log:: | ||
| 28 : | * abstract class which writes message into browser in usual PHP maner. | ||
| 29 : | * This may be useful because when you use PEAR::setErrorHandling in | ||
| 30 : | * PEAR_ERROR_CALLBACK mode error messages are not displayed by | ||
| 31 : | * PHP error handler. | ||
| 32 : | * | ||
| 33 : | * @author Paul Yanchenko <pusher@inaco.ru> | ||
| 34 : | * @since Log 1.8.0 | ||
| 35 : | * @package Log | ||
| 36 : | * | ||
| 37 : | * @example display.php Using the display handler. | ||
| 38 : | */ | ||
| 39 : | class Log_display extends vmLog | ||
| 40 : | { | ||
| 41 : | |||
| 42 : | /** | ||
| 43 : | * String used to represent a line break. | ||
| 44 : | * @var string | ||
| 45 : | * @access private | ||
| 46 : | */ | ||
| 47 : | var $_linebreak = "<br />\n"; | ||
| 48 : | |||
| 49 : | /** | ||
| 50 : | * Flag to enable or disable buffering. | ||
| 51 : | * @var boolean | ||
| 52 : | * @access private | ||
| 53 : | */ | ||
| 54 : | var $_buffering = true; | ||
| 55 : | |||
| 56 : | /** | ||
| 57 : | * Array to store messages when buffering is enabled | ||
| 58 : | * | ||
| 59 : | * @var array | ||
| 60 : | * @access private | ||
| 61 : | */ | ||
| 62 : | var $_messages = array(); | ||
| 63 : | |||
| 64 : | /** | ||
| 65 : | * Counts messages in the message array | ||
| 66 : | * @var int | ||
| 67 : | */ | ||
| 68 : | var $_count = 0; | ||
| 69 : | |||
| 70 : | /** | ||
| 71 : | * Constructs a new Log_display object. | ||
| 72 : | * | ||
| 73 : | * @param string $name Ignored. | ||
| 74 : | * @param string $ident The identity string. | ||
| 75 : | * @param array $conf The configuration array. | ||
| 76 : | * @param int $level Log messages up to and including this level. | ||
| 77 : | * @access public | ||
| 78 : | */ | ||
| 79 : | function Log_display($name = '', $ident = '', $conf = array(), | ||
| 80 : | $level = PEAR_LOG_TIP) | ||
| 81 : | { | ||
| 82 : | $this->_id = md5(microtime()); | ||
| 83 : | $this->_ident = $ident; | ||
| 84 : | $this->_mask = vmLog::UPTO($level); | ||
| 85 : | |||
| 86 : | if (isset($conf['linebreak'])) { | ||
| 87 : | $this->_linebreak = $conf['linebreak']; | ||
| 88 : | } | ||
| 89 : | |||
| 90 : | if (isset($conf['buffering'])) { | ||
| 91 : | $this->_buffering = $conf['buffering']; | ||
| 92 : | } | ||
| 93 : | } | ||
| 94 : | |||
| 95 : | /** | ||
| 96 : | * Writes $message to the text browser. Also, passes the message | ||
| 97 : | * along to any Log_observer instances that are observing this Log. | ||
| 98 : | * | ||
| 99 : | * @param mixed $message String or object containing the message to log. | ||
| 100 : | * @param string $priority The priority of the message. Valid | ||
| 101 : | * values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT, | ||
| 102 : | * PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING, | ||
| 103 : | * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG. | ||
| 104 : | * @return boolean True on success or false on failure. | ||
| 105 : | * @access public | ||
| 106 : | */ | ||
| 107 : | function log($message, $priority = null) | ||
| 108 : | { | ||
| 109 : | /* If a priority hasn't been specified, use the default value. */ | ||
| 110 : | if ($priority === null) { | ||
| 111 : | $priority = $this->_priority; | ||
| 112 : | } | ||
| 113 : | |||
| 114 : | /* Abort early if the priority is above the maximum logging level. */ | ||
| 115 : | if (!$this->_isMasked($priority)) { | ||
| 116 : | return false; | ||
| 117 : | } | ||
| 118 : | $this->_ticker++; | ||
| 119 : | |||
| 120 : | if( $priority >= PEAR_LOG_ERR ) { | ||
| 121 : | defined( '_VM_LOG_ERRORS' ) or define( '_VM_LOG_ERRORS', 1); | ||
| 122 : | } | ||
| 123 : | /* Extract the string representation of the message. */ | ||
| 124 : | $message = $this->_extractMessage($message); | ||
| 125 : | |||
| 126 : | // Store the log message and its priority | ||
| 127 : | $this->_messages[$this->_count]['priority'] = $priority; | ||
| 128 : | $this->_messages[$this->_count]['message'] = $message; | ||
| 129 : | $this->_count++; | ||
| 130 : | |||
| 131 : | if( !$this->_buffering ) { | ||
| 132 : | |||
| 133 : | $this->printLog(); | ||
| 134 : | } | ||
| 135 : | /* Notify observers about this log message. */ | ||
| 136 : | $this->_announce(array('priority' => $priority, 'message' => $message)); | ||
| 137 : | |||
| 138 : | return true; | ||
| 139 : | } | ||
| 140 : | /** | ||
| 141 : | * Formats a message depending on its priority | ||
| 142 : | * | ||
| 143 : | * @param string $message | ||
| 144 : | * @param int $priority | ||
| 145 : | * @return formatted HTML code | ||
| 146 : | */ | ||
| 147 : | function formatOutput( $message, $priority) { | ||
| 148 : | if( $priority >= PEAR_LOG_TIP) { | ||
| 149 : | return '<div class="shop_tip">'. $message . '</div>'; | ||
| 150 : | } | ||
| 151 : | elseif( $priority >= PEAR_LOG_DEBUG) { | ||
| 152 : | return '<div class="shop_debug">'. $message . '</div>'; | ||
| 153 : | } | ||
| 154 : | elseif( $priority >= PEAR_LOG_INFO) { | ||
| 155 : | return '<div class="shop_info">'. $message . '</div>'; | ||
| 156 : | } | ||
| 157 : | elseif( $priority >= PEAR_LOG_WARNING ) { | ||
| 158 : | return '<div class="shop_warning">'. $message . '</div>'; | ||
| 159 : | } | ||
| 160 : | elseif( $priority >= PEAR_LOG_ERR ) { | ||
| 161 : | return '<div class="shop_error">'. $message . '</div>'; | ||
| 162 : | } | ||
| 163 : | elseif( $priority >= PEAR_LOG_CRIT ) { | ||
| 164 : | return '<div class="shop_critical">'. $message . '</div>'; | ||
| 165 : | } | ||
| 166 : | } | ||
| 167 : | /** | ||
| 168 : | * Flush the _messages array and print all messages | ||
| 169 : | * @author Soeren Eberhardt | ||
| 170 : | */ | ||
| 171 : | function printLog( $priority = null ) { | ||
| 172 : | $output = ""; | ||
| 173 : | if( $this->_count > 10 && DEBUG) { | ||
| 174 : | // Wrap the messages into a scrollable div field | ||
| 175 : | $output .= '<div style="width:90%; overflow:auto; height:150px;">'; | ||
| 176 : | } | ||
| 177 : | foreach( $this->_messages as $message ) { | ||
| 178 : | if( ( $priority === null || $priority <= $message['priority'] ) | ||
| 179 : | && $message['priority'] !== PEAR_LOG_DEBUG | ||
| 180 : | || ( $message['priority'] === PEAR_LOG_DEBUG && DEBUG == '1')) { | ||
| 181 : | $output .= $this->formatOutput( | ||
| 182 : | '<b>' . ucfirst($this->priorityToString($message['priority'])) . '</b>: '. | ||
| 183 : | nl2br(htmlspecialchars($message['message'])) | ||
| 184 : | . $this->_linebreak, | ||
| 185 : | $message['priority'] | ||
| 186 : | ); | ||
| 187 : | } | ||
| 188 : | } | ||
| 189 : | if( $this->_count > 10 ) { | ||
| 190 : | $output .= '</div>'; | ||
| 191 : | } | ||
| 192 : | $this->_count = 0; | ||
| 193 : | $this->_messages = array(); | ||
| 194 : | if( $output ) { | ||
| 195 : | echo $output . $this->_linebreak; | ||
| 196 : | } | ||
| 197 : | } | ||
| 198 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

