Merge branch 'fixes' into main/rendor-staging
[ryzomcore.git] / web / public_php / api / common / logger.php
blob7599c62c9ce3a937151aabcce6e20a18832f9fc0
1 <?php
3 /* Copyright (C) 2009 Winch Gate Property Limited
5 * This file is part of ryzom_api.
6 * ryzom_api is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * ryzom_api is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with ryzom_api. If not, see <http://www.gnu.org/licenses/>.
20 class ryLogger {
22 public $enable = false;
23 private $logs = array();
24 private static $_instance = NULL;
26 public static function getInstance() {
27 if (self::$_instance === NULL)
28 self::$_instance = new ryLogger();
29 return self::$_instance;
32 function addLog($log, $indent=NULL) {
33 if ($indent !== NULL)
34 $this->log_indent += $indent;
35 if ($log) {
36 $tabs = str_repeat(" ", $this->log_indent);
37 $a = $tabs.str_replace("\n", "\n ".$tabs, $log);
38 $this->logs[] = '<font color="#00FF00">'.$a.'</font>';
42 function addPrint($log, $color='#FFFF00') {
43 $this->logs[] = '<font color="'.$color.'">'.$log.'</font>';
46 function addError($log) {
47 $this->logs[] = '<font color="#FF5500"> ERROR: '.$log.'</font>';
50 function getLogs() {
51 $ret = '';
52 if ($this->logs && $this->enable) {
53 $ret = '<b>Debug</b><br /><br /><pre style="overflow:auto; width:100%">'. implode('<br />', $this->logs).'</pre>';
54 $this->logs = array();
56 return $ret;
60 function _log() {
61 return ryLogger::getInstance();