10 define(
'PEAR_LOG_EMERG', 0);
11 define(
'PEAR_LOG_ALERT', 1);
12 define(
'PEAR_LOG_CRIT', 2);
13 define(
'PEAR_LOG_ERR', 3);
14 define(
'PEAR_LOG_WARNING', 4);
15 define(
'PEAR_LOG_NOTICE', 5);
16 define(
'PEAR_LOG_INFO', 6);
17 define(
'PEAR_LOG_DEBUG', 7);
19 define(
'PEAR_LOG_ALL', 0xffffffff);
20 define(
'PEAR_LOG_NONE', 0x00000000);
23 define(
'PEAR_LOG_TYPE_SYSTEM', 0);
24 define(
'PEAR_LOG_TYPE_MAIL', 1);
25 define(
'PEAR_LOG_TYPE_DEBUG', 2);
26 define(
'PEAR_LOG_TYPE_FILE', 3);
96 '%{priority}' =>
'%3$s',
97 '%{message}' =>
'%4$s',
100 '%{function}' =>
'%7$s',
101 '%{class}' =>
'%8$s',
119 if (version_compare(PHP_VERSION,
'5.0.0',
'ge')) {
120 return class_exists($class,
false);
123 return class_exists($class);
154 $handler = strtolower($handler);
155 $class =
'Log_' . $handler;
156 $classfile =
'Log/' . $handler .
'.php';
164 include_once $classfile;
169 $obj =
new $class(
$name, $ident, $conf, $level);
217 if (!isset($instances)) $instances = array();
219 $signature = serialize(array($handler,
$name, $ident, $conf, $level));
220 if (!isset($instances[$signature])) {
225 return $instances[$signature];
259 function log($message, $priority = null)
426 if (is_object($message)) {
427 if (method_exists($message,
'getmessage')) {
428 $message = $message->getMessage();
429 }
else if (method_exists($message,
'tostring')) {
430 $message = $message->toString();
431 }
else if (method_exists($message,
'__tostring')) {
432 if (version_compare(PHP_VERSION,
'5.0.0',
'ge')) {
433 $message = (string)$message;
435 $message = $message->__toString();
438 $message = var_export($message,
true);
440 }
else if (is_array($message)) {
441 if (isset($message[
'message'])) {
442 if (is_scalar($message[
'message'])) {
443 $message = $message[
'message'];
445 $message = var_export($message[
'message'],
true);
448 $message = var_export($message,
true);
450 }
else if (is_bool($message) || $message === NULL) {
451 $message = var_export($message,
true);
475 $bt = debug_backtrace();
481 $class = isset($bt[$depth+1][
'class']) ? $bt[$depth+1][
'class'] : null;
482 if ($class !== null && strcasecmp($class,
'Log_composite') == 0) {
484 $class = isset($bt[$depth + 1]) ? $bt[$depth + 1][
'class'] : null;
494 $file = isset($bt[$depth]) ? $bt[$depth][
'file'] : null;
495 $line = isset($bt[$depth]) ? $bt[$depth][
'line'] : 0;
496 $func = isset($bt[$depth + 1]) ? $bt[$depth + 1][
'function'] : null;
502 if (in_array($func, array(
'emerg',
'alert',
'crit',
'err',
'warning',
503 'notice',
'info',
'debug'))) {
504 $file = isset($bt[$depth + 1]) ? $bt[$depth + 1][
'file'] : null;
505 $line = isset($bt[$depth + 1]) ? $bt[$depth + 1][
'line'] : 0;
506 $func = isset($bt[$depth + 2]) ? $bt[$depth + 2][
'function'] : null;
513 if (is_null($func)) {
518 return array(
$file, $line, $func, $class);
536 if (preg_match(
'/%[5678]/', $format)) {
545 return sprintf($format,
551 isset($line) ? $line :
'',
552 isset($func) ? $func :
'',
553 isset($class) ? $class :
'');
579 return $levels[$priority];
608 return $levels[strtolower(
$name)];
625 return (1 << $priority);
682 return ((1 << ($priority + 1)) - 1);
697 $this->_mask = $mask;
728 return (
Log::MASK($priority) & $this->_mask);
754 $this->_priority = $priority;
771 if (!is_a($observer,
'Log_observer')) {
775 $this->_listeners[$observer->_id] = &$observer;
793 if (!is_a($observer,
'Log_observer') ||
794 !isset($this->_listeners[$observer->_id])) {
798 unset($this->_listeners[$observer->_id]);
813 foreach ($this->_listeners as $id => $listener) {
814 if ($event[
'priority'] <= $this->_listeners[$id]->_priority) {
815 $this->_listeners[$id]->notify($event);
843 $this->_ident = $ident;