2013-04-16 15:41:31 +00:00
|
|
|
<?php
|
|
|
|
class Logger {
|
2013-04-19 05:45:43 +00:00
|
|
|
private static $instance;
|
|
|
|
private $adapter;
|
2013-04-16 15:41:31 +00:00
|
|
|
|
2013-04-16 16:16:15 +00:00
|
|
|
public static $errornames = array(
|
|
|
|
1 => 'E_ERROR',
|
2013-04-16 15:41:31 +00:00
|
|
|
2 => 'E_WARNING',
|
2013-04-16 16:34:20 +00:00
|
|
|
4 => 'E_PARSE',
|
2013-04-16 15:41:31 +00:00
|
|
|
8 => 'E_NOTICE',
|
2013-04-16 16:34:20 +00:00
|
|
|
16 => 'E_CORE_ERROR',
|
|
|
|
32 => 'E_CORE_WARNING',
|
|
|
|
64 => 'E_COMPILE_ERROR',
|
|
|
|
128 => 'E_COMPILE_WARNING',
|
2013-04-16 15:41:31 +00:00
|
|
|
256 => 'E_USER_ERROR',
|
|
|
|
512 => 'E_USER_WARNING',
|
|
|
|
1024 => 'E_USER_NOTICE',
|
|
|
|
2048 => 'E_STRICT',
|
|
|
|
4096 => 'E_RECOVERABLE_ERROR',
|
|
|
|
8192 => 'E_DEPRECATED',
|
|
|
|
16384 => 'E_USER_DEPRECATED',
|
|
|
|
32767 => 'E_ALL');
|
|
|
|
|
|
|
|
function log_error($errno, $errstr, $file, $line, $context) {
|
2013-04-19 05:45:43 +00:00
|
|
|
if ($errno == E_NOTICE) return false;
|
|
|
|
|
|
|
|
if ($this->adapter)
|
|
|
|
return $this->adapter->log_error($errno, $errstr, $file, $line, $context);
|
|
|
|
else
|
|
|
|
return false;
|
2013-04-16 15:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function log($string) {
|
2013-04-19 05:45:43 +00:00
|
|
|
if ($this->adapter)
|
2018-09-10 18:26:28 +00:00
|
|
|
return $this->adapter->log_error(E_USER_NOTICE, $string, '', 0, '');
|
2013-04-19 05:45:43 +00:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function __clone() {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
function __construct() {
|
|
|
|
switch (LOG_DESTINATION) {
|
|
|
|
case "sql":
|
|
|
|
$this->adapter = new Logger_SQL();
|
|
|
|
break;
|
|
|
|
case "syslog":
|
|
|
|
$this->adapter = new Logger_Syslog();
|
|
|
|
break;
|
2018-08-15 12:08:31 +00:00
|
|
|
case "stdout":
|
|
|
|
$this->adapter = new Logger_Stdout();
|
|
|
|
break;
|
2013-04-19 05:45:43 +00:00
|
|
|
default:
|
|
|
|
$this->adapter = false;
|
|
|
|
}
|
2013-04-16 15:41:31 +00:00
|
|
|
}
|
2013-04-19 05:45:43 +00:00
|
|
|
|
|
|
|
public static function get() {
|
|
|
|
if (self::$instance == null)
|
|
|
|
self::$instance = new self();
|
|
|
|
|
|
|
|
return self::$instance;
|
|
|
|
}
|
|
|
|
|
2018-08-15 12:08:31 +00:00
|
|
|
}
|