[ Index ] |
|
Code source de vtiger CRM 5.0.2 |
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 /** 21 * @ignore 22 */ 23 if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..'); 24 25 /** 26 */ 27 require_once(LOG4PHP_DIR . '/spi/LoggerLocationInfo.php'); 28 require_once (LOG4PHP_DIR . '/LoggerManager.php'); 29 require_once(LOG4PHP_DIR . '/LoggerMDC.php'); 30 require_once(LOG4PHP_DIR . '/LoggerNDC.php'); 31 32 /** 33 * The internal representation of logging event. 34 * 35 * @author VxR <vxr@vxr.it> 36 * @version $Revision: 1.16 $ 37 * @package log4php 38 * @subpackage spi 39 */ 40 class LoggerLoggingEvent { 41 42 /** 43 * @var string Fully Qualified Class Name of the calling category class. 44 */ 45 var $fqcn; 46 47 /** 48 * @var Logger reference 49 */ 50 var $logger = null; 51 52 /** 53 * The category (logger) name. 54 * This field will be marked as private in future 55 * releases. Please do not access it directly. 56 * Use the {@link getLoggerName()} method instead. 57 * @deprecated 58 */ 59 var $categoryName; 60 61 /** 62 * Level of logging event. 63 * <p> This field should not be accessed directly. You shoud use the 64 * {@link getLevel()} method instead. 65 * 66 * @deprecated 67 * @var LoggerLevel 68 */ 69 var $level; 70 71 /** 72 * @var string The nested diagnostic context (NDC) of logging event. 73 */ 74 var $ndc; 75 76 /** 77 * Have we tried to do an NDC lookup? If we did, there is no need 78 * to do it again. Note that its value is always false when 79 * serialized. Thus, a receiving SocketNode will never use it's own 80 * (incorrect) NDC. See also writeObject method. 81 * @var boolean 82 */ 83 var $ndcLookupRequired = true; 84 85 /** 86 * Have we tried to do an MDC lookup? If we did, there is no need 87 * to do it again. Note that its value is always false when 88 * serialized. See also the getMDC and getMDCCopy methods. 89 * @var boolean 90 */ 91 var $mdcCopyLookupRequired = true; 92 93 /** 94 * @var mixed The application supplied message of logging event. 95 */ 96 var $message; 97 98 /** 99 * The application supplied message rendered through the log4php 100 * objet rendering mechanism. At present renderedMessage == message. 101 * @var string 102 */ 103 var $renderedMessage; 104 105 /** 106 * The name of thread in which this logging event was generated. 107 * log4php saves here the process id via {@link PHP_MANUAL#getmypid getmypid()} 108 * @var mixed 109 */ 110 var $threadName = null; 111 112 /** 113 * The number of seconds elapsed from 1/1/1970 until logging event 114 * was created plus microseconds if available. 115 * @var float 116 */ 117 var $timeStamp; 118 119 /** 120 * @var LoggerLocationInfo Location information for the caller. 121 */ 122 var $locationInfo = null; 123 124 // Serialization 125 /* 126 var $serialVersionUID = -868428216207166145L; 127 var $PARAM_ARRAY = array(); 128 var $TO_LEVEL = "toLevel"; 129 var $TO_LEVEL_PARAMS = null; 130 var $methodCache = array(); // use a tiny table 131 */ 132 133 /** 134 * Instantiate a LoggingEvent from the supplied parameters. 135 * 136 * <p>Except {@link $timeStamp} all the other fields of 137 * LoggerLoggingEvent are filled when actually needed. 138 * 139 * @param string $fqcn name of the caller class. 140 * @param mixed &$logger The {@link Logger} category of this event or the logger name. 141 * @param LoggerLevel $priority The level of this event. 142 * @param mixed $message The message of this event. 143 * @param integer $timeStamp the timestamp of this logging event. 144 */ 145 function LoggerLoggingEvent($fqcn, &$logger, $priority, $message, $timeStamp = null) 146 { 147 $this->fqcn = $fqcn; 148 if (is_a($logger, 'logger')) { 149 $this->logger =& $logger; 150 $this->categoryName = $logger->getName(); 151 } else { 152 $this->categoryName = (string)$logger; 153 } 154 $this->level = $priority; 155 $this->message = $message; 156 if ($timeStamp !== null and is_float($timeStamp)) { 157 $this->timeStamp = $timeStamp; 158 } else { 159 if (function_exists('microtime')) { 160 list($usecs, $secs) = explode(' ', microtime()); 161 $this->timeStamp = ((float)$usecs + (float)$secs); 162 } else { 163 $this->timeStamp = time(); 164 } 165 } 166 } 167 168 /** 169 * Set the location information for this logging event. The collected 170 * information is cached for future use. 171 * 172 * <p>This method uses {@link PHP_MANUAL#debug_backtrace debug_backtrace()} function (if exists) 173 * to collect informations about caller.</p> 174 * <p>It only recognize informations generated by {@link Logger} and its subclasses.</p> 175 * @return LoggerLocationInfo 176 */ 177 function getLocationInformation() 178 { 179 if($this->locationInfo === null) { 180 181 $locationInfo = array(); 182 183 if (function_exists('debug_backtrace')) { 184 $trace = debug_backtrace(); 185 $prevHop = null; 186 // make a downsearch to identify the caller 187 $hop = array_pop($trace); 188 while ($hop !== null) { 189 $className = @$hop['class']; 190 if ( !empty($className) and ($className == 'logger' or get_parent_class($className) == 'logger') ) { 191 $locationInfo['line'] = $hop['line']; 192 $locationInfo['file'] = $hop['file']; 193 break; 194 } 195 $prevHop = $hop; 196 $hop = array_pop($trace); 197 } 198 $locationInfo['class'] = isset($prevHop['class']) ? $prevHop['class'] : 'main'; 199 if (isset($prevHop['function']) and 200 $prevHop['function'] !== 'include' and 201 $prevHop['function'] !== 'include_once' and 202 $prevHop['function'] !== 'require' and 203 $prevHop['function'] !== 'require_once') { 204 205 $locationInfo['function'] = $prevHop['function']; 206 } else { 207 $locationInfo['function'] = 'main'; 208 } 209 } 210 211 $this->locationInfo = new LoggerLocationInfo($locationInfo, $this->fqcn); 212 } 213 return $this->locationInfo; 214 } 215 216 /** 217 * Return the level of this event. Use this form instead of directly 218 * accessing the {@link $level} field. 219 * @return LoggerLevel 220 */ 221 function getLevel() 222 { 223 return $this->level; 224 } 225 226 /** 227 * Return the name of the logger. Use this form instead of directly 228 * accessing the {@link $categoryName} field. 229 * @return string 230 */ 231 function getLoggerName() 232 { 233 return $this->categoryName; 234 } 235 236 /** 237 * Return the message for this logging event. 238 * 239 * <p>Before serialization, the returned object is the message 240 * passed by the user to generate the logging event. After 241 * serialization, the returned value equals the String form of the 242 * message possibly after object rendering. 243 * @return mixed 244 */ 245 function getMessage() 246 { 247 if($this->message !== null) { 248 return $this->message; 249 } else { 250 return $this->getRenderedMessage(); 251 } 252 } 253 254 /** 255 * This method returns the NDC for this event. It will return the 256 * correct content even if the event was generated in a different 257 * thread or even on a different machine. The {@link LoggerNDC::get()} method 258 * should <b>never</b> be called directly. 259 * @return string 260 */ 261 function getNDC() 262 { 263 if ($this->ndcLookupRequired) { 264 $this->ndcLookupRequired = false; 265 $this->ndc = implode(' ',LoggerNDC::get()); 266 } 267 return $this->ndc; 268 } 269 270 271 /** 272 * Returns the the context corresponding to the <code>key</code> 273 * parameter. 274 * @return string 275 */ 276 function getMDC($key) 277 { 278 return LoggerMDC::get($key); 279 } 280 281 /** 282 * Render message. 283 * @return string 284 */ 285 function getRenderedMessage() 286 { 287 if($this->renderedMessage === null and $this->message !== null) { 288 if (is_string($this->message)) { 289 $this->renderedMessage = $this->message; 290 } else { 291 if ($this->logger !== null) { 292 $repository =& $this->logger->getLoggerRepository(); 293 } else { 294 $repository =& LoggerManager::getLoggerRepository(); 295 } 296 if (method_exists($repository, 'getrenderermap')) { 297 $rendererMap =& $repository->getRendererMap(); 298 $this->renderedMessage= $rendererMap->findAndRender($this->message); 299 } else { 300 $this->renderedMessage = (string)$this->message; 301 } 302 } 303 } 304 return $this->renderedMessage; 305 } 306 307 /** 308 * Returns the time when the application started, in seconds 309 * elapsed since 01.01.1970 plus microseconds if available. 310 * 311 * @return float 312 * @static 313 */ 314 function getStartTime() 315 { 316 static $startTime; 317 318 if (!isset($startTime)) { 319 if (function_exists('microtime')) { 320 list($usec, $sec) = explode(' ', microtime()); 321 $startTime = ((float)$usec + (float)$sec); 322 } else { 323 $startTime = time(); 324 } 325 } 326 return $startTime; 327 } 328 329 /** 330 * @return float 331 */ 332 function getTimeStamp() 333 { 334 return $this->timeStamp; 335 } 336 337 /** 338 * @return mixed 339 */ 340 function getThreadName() 341 { 342 if ($this->threadName === null) 343 $this->threadName = (string)getmypid(); 344 return $this->threadName; 345 } 346 347 /** 348 * @return mixed null 349 */ 350 function getThrowableInformation() 351 { 352 return null; 353 } 354 355 /** 356 * Serialize this object 357 * @return string 358 */ 359 function toString() 360 { 361 serialize($this); 362 } 363 364 /** 365 * Avoid serialization of the {@link $logger} object 366 */ 367 function __sleep() 368 { 369 return array( 370 'fqcn','categoryName', 371 'level', 372 'ndc','ndcLookupRequired', 373 'message','renderedMessage', 374 'threadName', 375 'timestamp', 376 'locationInfo' 377 ); 378 } 379 380 } 381 382 LoggerLoggingEvent::getStartTime(); 383 384 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 10:22:19 2007 | par Balluche grâce à PHPXref 0.7 |