88 Logger::getInstance()->addLogger($this);
105 if (!isset($instance)) {
107 $instance =
new $class();
133 $this->activated =
false;
146 error_reporting(E_ALL | E_STRICT);
148 if ($this->configs && array_key_exists(
'logger_enable', $this->configs)) {
149 if ($this->configs[
'logger_popup']) {
150 $this->usePopup =
true;
153 $this->activated =
true;
174 $this->activated =
false;
184 static $addedResource =
false;
186 if ($this->activated && !$addedResource) {
194 $addedResource =
true;
208 if ($this->activated) {
209 $this->logstart[
$name] = microtime(
true);
222 if ($this->activated) {
223 $this->logend[
$name] = microtime(
true);
239 if ($this->activated) {
240 $this->queries[] = array(
241 'sql' =>
$sql,
'error' =>
$error,
'errno' => $errno,
'query_time' => $query_time
257 if ($this->activated) {
258 $this->blocks[] = array(
'name' =>
$name,
'cached' => $cached,
'cachetime' => $cachetime);
272 if ($this->activated) {
273 $this->extra[] = array(
'name' =>
$name,
'msg' =>
$msg);
286 if ($this->activated) {
287 $this->deprecated[] =
$msg;
300 if ($this->activated) {
303 'Exception: ' . $e->getMessage() .
' - ' .
304 $this->
sanitizePath($e->getFile()) .
' ' . $e->getLine()
340 if (!$this->renderingEnabled) {
341 ob_start(array(&$this,
'render'));
342 $this->renderingEnabled =
true;
355 if (!$this->activated) {
359 $log = $this->
dump($this->usePopup ?
'popup' :
'');
360 $this->renderingEnabled = $this->activated =
false;
362 $pattern =
'<!--{xo-logger-output}-->';
363 $pos = strpos($output, $pattern);
364 if ($pos !==
false) {
365 return substr($output, 0, $pos) . $log . substr($output, $pos + strlen($pattern));
367 return $output . $log;
378 public function dump($mode =
'')
385 if ($mode ==
'popup') {
386 $dump = $this->
dump(
'');
388 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
393 <meta name="generator" content="XOOPS" />
394 <link rel="stylesheet" type="text/css" media="all" href="' .
$xoops->getCss(
$xoops->getConfig(
'theme_set')) .
'" />
397 <div style="text-align:center;">
398 <input class="formButton" value="' .
XoopsLocale::A_CLOSE .
'" type="button" onclick="javascript:window.close();" />
402 <script type="text/javascript">
403 debug_window = openWithSelfMain("about:blank", "popup", 680, 450, true);
404 debug_window.document.clear();
406 $lines = preg_split(
"/(\r\n|\r|\n)( *)/",
$content);
407 foreach ($lines as $line) {
408 $ret .=
"\n" .
'debug_window.document.writeln("'
409 . str_replace(array(
'"',
'</'), array(
'\"',
'<\/'), $line) .
'");';
412 debug_window.focus();
413 debug_window.document.close();
436 if (function_exists(
'memory_get_usage')) {
437 $memory = memory_get_usage() .
' bytes';
439 if (strtoupper(substr(PHP_OS, 0, 3)) ===
'WIN') {
441 exec(
'tasklist /FI "PID eq ' . getmypid() .
'" /FO LIST', $out);
442 if (isset($out[5])) {
452 $views = array(
'errors',
'deprecated',
'queries',
'blocks',
'extra');
453 $ret .=
"\n<div id=\"xo-logger-output\">\n<div id='xo-logger-tabs'>\n";
454 $ret .=
"<a href='javascript:xoSetLoggerView(\"none\")'>" .
_MD_LOGGER_NONE .
"</a>\n";
455 $ret .=
"<a href='javascript:xoSetLoggerView(\"\")'>" .
_MD_LOGGER_ALL .
"</a>\n";
456 foreach ($views as
$view) {
457 $count = count($this->$view);
458 $ret .=
"<a href='javascript:xoSetLoggerView(\"$view\")'>" . constant(
'_MD_LOGGER_' . strtoupper($view)) .
" ($count)</a>\n";
460 $count = count($this->logstart);
461 $ret .=
"<a href='javascript:xoSetLoggerView(\"timers\")'>" .
_MD_LOGGER_TIMERS .
"($count)</a>\n";
465 if (empty($mode) || $mode ==
'errors') {
467 $ret .=
'<table id="xo-logger-errors" class="outer"><thead><tr><th>' .
_MD_LOGGER_ERRORS .
'</th></tr></thead><tbody>';
468 foreach ($this->errors as
$error) {
469 $ret .=
"\n<tr><td class='$class'>";
471 $ret .=
"<br />\n</td></tr>";
472 $class = ($class ==
'odd') ?
'even' :
'odd';
474 $ret .=
"\n</tbody></table>\n";
477 if (empty($mode) || $mode ==
'deprecated') {
479 $ret .=
'<table id="xo-logger-deprecated" class="outer"><thead><tr><th>' .
_MD_LOGGER_DEPRECATED .
'</th></tr></thead><tbody>';
480 foreach ($this->deprecated as $message) {
481 $ret .=
"\n<tr><td class='$class'>";
483 $ret .=
"<br />\n</td></tr>";
484 $class = ($class ==
'odd') ?
'even' :
'odd';
486 $ret .=
"\n</tbody></table>\n";
489 if (empty($mode) || $mode ==
'queries') {
491 $ret .=
'<table id="xo-logger-queries" class="outer"><thead><tr><th>' .
_MD_LOGGER_QUERIES .
'</th></tr></thead><tbody>';
494 foreach ($this->queries as $q) {
495 $sql = preg_replace($pattern,
'', $q[
'sql']);
496 $query_time = isset($q[
'query_time']) ? sprintf(
'%0.6f - ', $q[
'query_time']) :
'';
498 if (isset($q[
'error'])) {
499 $ret .=
'<tr class="' . $class .
'"><td><span style="color:#ff0000;">' . $query_time . htmlentities(
$sql) .
'<br /><strong>Error number:</strong> ' . $q[
'errno'] .
'<br /><strong>Error message:</strong> ' . $q[
'error'] .
'</span></td></tr>';
501 $ret .=
'<tr class="' . $class .
'"><td>' . $query_time . htmlentities(
$sql) .
'</td></tr>';
504 $class = ($class ==
'odd') ?
'even' :
'odd';
506 $ret .=
'</tbody><tfoot><tr class="foot"><td>' .
_MD_LOGGER_TOTAL .
': <span style="color:#ff0000;">' . count($this->queries) .
'</span></td></tr></tfoot></table>';
508 if (empty($mode) || $mode ==
'blocks') {
510 $ret .=
'<table id="xo-logger-blocks" class="outer"><thead><tr><th>' .
_MD_LOGGER_BLOCKS .
'</th></tr></thead><tbody>';
511 foreach ($this->blocks as $b) {
513 $ret .=
'<tr><td class="' . $class .
'"><strong>' . $b[
'name'] .
':</strong> ' . sprintf(
_MD_LOGGER_CACHED, intval($b[
'cachetime'])) .
'</td></tr>';
515 $ret .=
'<tr><td class="' . $class .
'"><strong>' . $b[
'name'] .
':</strong> ' .
_MD_LOGGER_NOT_CACHED .
'</td></tr>';
517 $class = ($class ==
'odd') ?
'even' :
'odd';
519 $ret .=
'</tbody><tfoot><tr class="foot"><td>' .
_MD_LOGGER_TOTAL .
': <span style="color:#ff0000;">' . count($this->blocks) .
'</span></td></tr></tfoot></table>';
521 if (empty($mode) || $mode ==
'extra') {
523 $ret .=
'<table id="xo-logger-extra" class="outer"><thead><tr><th>' .
_MD_LOGGER_EXTRA .
'</th></tr></thead><tbody>';
524 foreach ($this->extra as $ex) {
525 $ret .=
'<tr><td class="' . $class .
'"><strong>';
526 $ret .= htmlspecialchars($ex[
'name']) .
':</strong> ' . htmlspecialchars($ex[
'msg']);
527 $ret .=
'</td></tr>';
528 $class = ($class ==
'odd') ?
'even' :
'odd';
530 $ret .=
'</tbody></table>';
532 if (empty($mode) || $mode ==
'timers') {
534 $ret .=
'<table id="xo-logger-timers" class="outer"><thead><tr><th>' .
_MD_LOGGER_TIMERS .
'</th></tr></thead><tbody>';
535 foreach ($this->logstart as $k => $v) {
536 $ret .=
'<tr><td class="' . $class .
'"><strong>';
537 $ret .= sprintf(
_MD_LOGGER_TIMETOLOAD, htmlspecialchars($k) .
'</strong>',
'<span style="color:#ff0000;">' . sprintf(
"%.03f", $this->
dumpTime($k)) .
'</span>');
538 $ret .=
'</td></tr>';
539 $class = ($class ==
'odd') ?
'even' :
'odd';
541 $ret .=
'</tbody></table>';
547 <script type=
"text/javascript">
548 function xoLogCreateCookie(name,value,days) {
550 var date =
new Date();
551 date.setTime(date.getTime()+(days*24*60*60*1000));
552 var expires =
"; expires="+date.toGMTString();
554 else var expires =
"";
555 document.cookie = name+
"="+value+expires+
"; path=/";
557 function xoLogReadCookie(name) {
558 var nameEQ = name +
"=";
559 var ca = document.cookie.split(
';');
560 for(var i=0;i < ca.length;i++) {
562 while (c.charAt(0)==
' ') c = c.substring(1,c.length);
563 if (c.indexOf(nameEQ) == 0)
return c.substring(nameEQ.length,c.length);
567 function xoLogEraseCookie(name) {
568 createCookie(name,
"",-1);
570 function xoSetLoggerView( name ) {
571 var
log = document.getElementById(
"xo-logger-output" );
574 for ( i=0; i!=log.childNodes.length; i++ ) {
575 elt = log.childNodes[i];
576 if ( elt.tagName && elt.tagName.toLowerCase() !=
'script' && elt.id !=
"xo-logger-tabs" ) {
577 elt.style.display = ( !name || elt.id ==
"xo-logger-" + name ) ?
"block" :
"none";
580 xoLogCreateCookie(
'XOLOGGERVIEW', name, 1 );
582 xoSetLoggerView( xoLogReadCookie(
'XOLOGGERVIEW' ) );
601 if (!$this->activated) {
605 if (!isset($this->logstart[
$name])) {
608 $stop = isset($this->logend[$name]) ? $this->logend[
$name] : microtime(
true);
612 unset($this->logstart[$name]);
613 unset($this->logend[$name]);
628 public function emergency($message, array $context = array())
630 if ($this->activated) {
631 $this->
log(LogLevel::EMERGENCY, $message, $context);
646 public function alert($message, array $context = array())
648 if ($this->activated) {
649 $this->
log(LogLevel::ALERT, $message, $context);
663 public function critical($message, array $context = array())
665 if ($this->activated) {
666 $this->
log(LogLevel::CRITICAL, $message, $context);
679 public function error($message, array $context = array())
681 if ($this->activated) {
682 $this->
log(LogLevel::ERROR, $message, $context);
697 public function warning($message, array $context = array())
699 if ($this->activated) {
712 public function notice($message, array $context = array())
714 if ($this->activated) {
715 $this->
log(LogLevel::NOTICE, $message, $context);
729 public function info($message, array $context = array())
731 if ($this->activated) {
732 $this->
log(LogLevel::INFO, $message, $context);
744 public function debug($message, array $context = array())
746 if ($this->activated) {
747 $this->
log(LogLevel::DEBUG, $message, $context);
760 public function log($level, $message, array $context = array())
762 if (!$this->activated) {
766 $this->errors[] = $message;
if(empty($settings['ROOT_PATH'])) elseif(empty($settings['DB_PARAMETERS'])) $error
error($message, array $context=array())
debug($message, array $context=array())
info($message, array $context=array())
log($level, $message, array $context=array())
addBlock($name, $cached=false, $cachetime=0)
if(!isset($_SESSION['RF']["view_type"])) if(isset($_GET['view'])) $view
startTime($name= 'XOOPS')
const _MD_LOGGER_NOT_CACHED
notice($message, array $context=array())
const _MD_LOGGER_MEM_USAGE
dumpTime($name= 'XOOPS', $unset=false)
addQuery($sql, $error=null, $errno=null, $query_time=null)
alert($message, array $context=array())
const _MD_LOGGER_DEPRECATED
const _MD_LOGGER_MEM_ESTIMATED
const _MD_LOGGER_TIMETOLOAD
critical($message, array $context=array())
const _MD_LOGGER_INCLUDED_FILES
if(!is_object($module)||!$module->getVar('isactive')) $msg
emergency($message, array $context=array())
warning($message, array $context=array())