24 defined(
'XOOPS_ROOT_PATH') or die('Restricted access');
42 var $blocks = array();
44 var $logstart = array();
45 var $logend = array();
47 var $deprecated = array();
52 var $usePopup =
false;
53 var $activated =
true;
58 var $renderingEnabled =
false;
63 function __construct()
70 function XoopsLogger()
87 static function &getInstance()
90 if (!isset($instance)) {
91 $instance =
new XoopsLogger();
93 set_error_handler(
'XoopsErrorHandler_HandleError');
104 function enableRendering()
106 if (!$this->renderingEnabled) {
107 ob_start(array(&$this ,
'render'));
108 $this->renderingEnabled =
true;
119 $now = explode(
' ', microtime());
120 return (
float) $now[0] + (float) $now[1];
128 function startTime($name =
'XOOPS')
131 $this->logstart[$name] = $this->microtime();
139 function stopTime($name =
'XOOPS')
142 $this->logend[$name] = $this->microtime();
152 function addQuery(
$sql,
$error = null, $errno = null, $query_time = null)
155 $this->queries[] = array(
'sql' =>
$sql ,
'error' =>
$error ,
'errno' => $errno,
'query_time' => $query_time);
165 function addBlock($name, $cached =
false, $cachetime = 0)
168 $this->blocks[] = array(
'name' => $name ,
'cached' => $cached ,
'cachetime' => $cachetime);
180 $this->extra[] = array(
'name' => $name ,
'msg' =>
$msg);
193 $this->deprecated[] =
$msg;
199 function handleError($errno, $errstr, $errfile, $errline)
201 if ($this->
activated && ($errno & error_reporting())) {
203 $this->errors[] = compact(
'errno',
'errstr',
'errfile',
'errline');
205 if ($errno == E_USER_ERROR) {
207 if (substr($errstr, 0,
'8') ==
'notrace:') {
209 $errstr = substr($errstr, 8);
212 if ($trace && function_exists(
'debug_backtrace')) {
214 $trace = debug_backtrace();
216 foreach ($trace as $step) {
217 if (isset($step[
'file'])) {
218 echo $this->sanitizePath($step[
'file']);
219 echo
' (' . $step[
'line'] .
")\n<br />";
234 $path = str_replace(array(
'\\' , XOOPS_ROOT_PATH , str_replace(
'\\',
'/', realpath(XOOPS_ROOT_PATH))), array(
'/' ,
'' ,
''),
$path);
241 function render($output)
248 $log = $this->dump($this->
usePopup ?
'popup' :
'');
249 $this->renderingEnabled = $this->
activated =
false;
250 $pattern =
'<!--{xo-logger-output}-->';
251 $pos = strpos($output, $pattern);
252 if (
$pos !==
false) {
253 return substr($output, 0,
$pos) . $log . substr($output,
$pos + strlen($pattern));
255 return $output . $log;
264 function dump($mode =
'')
266 include XOOPS_ROOT_PATH .
'/class/logger/render.php';
277 function dumpTime($name =
'XOOPS', $unset =
false)
282 if (!isset($this->logstart[$name])) {
285 $stop = isset($this->logend[$name]) ? $this->logend[$name] : $this->microtime();
286 $start = $this->logstart[$name];
289 unset($this->logstart[$name]);
305 function triggerError($errkey = 0, $errStr =
'', $errFile =
'', $errLine =
'', $errNo = 0)
307 $GLOBALS[
'xoopsLogger']->addDeprecated(
'\'$xoopsLogger->triggerError();\
' is deprecated since XOOPS 2.5.4');
309 if (!empty($errStr)) {
310 $errStr = sprintf($errStr,$errkey );
312 $errFile = $this->sanitizePath($errFile);
313 $this->handleError($errNo, $errStr, $errFile, $errLine);
323 $GLOBALS[
'xoopsLogger']->addDeprecated(
'\'$xoopsLogger->dumpAll();\
' is deprecated since XOOPS 2.5.4, please use \'$xoopsLogger->dump(\'\');\' instead.');
325 return $this->dump(
'');
333 function dumpBlocks()
335 $GLOBALS[
'xoopsLogger']->addDeprecated(
'\'$xoopsLogger->dumpBlocks();\
' is deprecated since XOOPS 2.5.4, please use \'$xoopsLogger->dump(\'blocks\');\' instead.');
337 return $this->dump(
'blocks');
347 $GLOBALS[
'xoopsLogger']->addDeprecated(
'\'$xoopsLogger->dumpExtra();\
' is deprecated since XOOPS 2.5.4, please use \'$xoopsLogger->dump(\'extra\');\' instead.');
349 return $this->dump(
'extra');
357 function dumpQueries()
359 $GLOBALS[
'xoopsLogger']->addDeprecated(
'\'$xoopsLogger->dumpQueries();\
' is deprecated since XOOPS 2.5.4, please use \'$xoopsLogger->dump(\'queries\');\' instead.');
361 return $this->dump(
'queries');
380 if ($errNo ==
'2048') {
385 $logger->handleError($errNo, $errStr, $errFile, $errLine, $errContext);