khanat-opennel-code/code/web/api/common/logger.php

44 lines
912 B
PHP
Raw Normal View History

2012-05-04 10:04:49 +00:00
<?php
class ryLogger {
public $enable = false;
private $logs;
private static $_instance = NULL;
public static function getInstance() {
if (self::$_instance === NULL)
self::$_instance = new ryLogger();
return self::$_instance;
}
function addLog($log, $indent=NULL) {
if ($indent !== NULL)
$this->log_indent += $indent;
if ($log) {
$tabs = str_repeat(" ", $this->log_indent);
$a = $tabs.str_replace("\n", "\n ".$tabs, $log);
$this->logs[] = '<font color="#00FF00">'.$a.'</font>';
}
}
function addPrint($log, $color='#FFFF00') {
$this->logs[] = '<font color="'.$color.'">'.$log.'</font>';
}
function addError($log) {
$this->logs[] = '<font color="#FF5500"> ERROR: '.$log.'</font>';
}
function getLogs() {
$ret = '';
if ($this->logs && $this->enable)
2012-05-04 16:33:59 +00:00
$ret = "<b>Debug</b>\n\n".implode("\n", $this->logs);
2012-05-04 10:04:49 +00:00
$this->logs = array();
return $ret;
}
}
?>