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);
151 function &
factory($handler, $name =
'', $ident =
'', $conf = array(),
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);
213 function &
singleton($handler, $name =
'', $ident =
'', $conf = array(),
217 if (!isset($instances)) $instances = array();
219 $signature = serialize(array($handler, $name, $ident, $conf, $level));
220 if (!isset($instances[$signature])) {
221 $instances[$signature] = &
Log::factory($handler, $name, $ident,
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;
err($message)
A convenience function for logging a error event.
_announce($event)
Informs each registered observer instance that a new message has been logged.
_getBacktraceVars($depth)
Using debug_backtrace(), returns the file, line, and enclosing function name of the source code conte...
flush()
Abstract implementation of the flush() method.
UPTO($priority)
Calculate the log mask for all priorities up to the given priority.
emerg($message)
A convenience function for logging a emergency event.
& factory($handler, $name='', $ident='', $conf=array(), $level=PEAR_LOG_DEBUG)
Attempts to return a concrete Log instance of type $handler.
setIdent($ident)
Sets this Log instance's identification string.
MAX($priority)
Calculate the log mask for all priorities less than or equal to the given priority.
crit($message)
A convenience function for logging a critical event.
getIdent()
Returns the current identification string.
alert($message)
A convenience function for logging an alert event.
stringToPriority($name)
Returns the the PEAR_LOG_* integer constant for the given string representation of a priority name...
setPriority($priority)
Sets the default priority to the specified value.
close()
Abstract implementation of the close() method.
isComposite()
Indicates whether this is a composite class.
setMask($mask)
Set and return the level mask for the current Log instance.
MASK($priority)
Calculate the log mask for the given priority.
MIN($priority)
Calculate the log mask for all priorities greater than or equal to the given priority.
getPriority()
Returns the current default priority.
& singleton($handler, $name='', $ident='', $conf=array(), $level=PEAR_LOG_DEBUG)
Attempts to return a reference to a concrete Log instance of type $handler, only creating a new insta...
foreach($mandatory_scripts as $file) $timestamp
_isMasked($priority)
Check if the given priority is included in the current level mask.
_extractMessage($message)
Returns the string representation of the message data.
detach($observer)
Removes a Log_observer instance from the list of observers.
priorityToString($priority)
Returns the string representation of a PEAR_LOG_* integer constant.
log($message, $priority=null)
Abstract implementation of the log() method.
_format($format, $timestamp, $priority, $message)
Produces a formatted log line based on a format string and a set of variables representing the curren...
open()
Abstract implementation of the open() method.
info($message)
A convenience function for logging a information event.
debug($message)
A convenience function for logging a debug event.
_classExists($class)
Utility function which wraps PHP's class_exists() function to ensure consistent behavior between PHP ...
warning($message)
A convenience function for logging a warning event.
notice($message)
A convenience function for logging a notice event.
attach(&$observer)
Adds a Log_observer instance to the list of observers that are listening for messages emitted by this...
getMask()
Returns the current level mask.