3 require_once 'PEAR.php';
4 require_once 'Log.php';
8 private static $irreco_log;
9 private static $php_level;
11 public static $critical;
13 public static $exception;
16 public static $database;
17 public static $server;
19 public static function getVarDump(&$var)
23 return ob_get_clean();
26 public static function init()
29 $conf = array('mode' => 0644,
30 'timeFormat' => '%Y-%m-%d %T');
33 if (!is_object(self
::$critical)) {
34 self
::$critical = Log
::singleton(
35 'file', $file, NULL, $conf);
38 /* Setup PHP error logging. */
39 if (!is_object(self
::$php)) {
40 self
::$php = Log
::singleton(
41 'file', $file, 'PHP', $conf);
43 array('IrrecoLog', 'phpErrorHandler'));
46 /* Setup PHP exception error logging. */
47 if (!is_object(self
::$exception)) {
48 self
::$exception = Log
::singleton(
49 'file', $file, 'EXCEPTION', $conf);
50 set_exception_handler(
51 array('IrrecoLog', 'phpExceptionHandler'));
54 /* Setup PEAR error logging. */
55 if (!is_object(self
::$pear)) {
56 self
::$pear = Log
::singleton(
57 'file', $file, 'PEAR', $conf);
58 PEAR
::setErrorHandling(PEAR_ERROR_CALLBACK
,
59 array('IrrecoLog', 'pearErrorHandler'));
63 if (!is_object(self
::$index)) {
64 self
::$index = Log
::singleton(
65 'file', $file, 'Index', $conf);
69 if (!is_object(self
::$database)) {
70 self
::$database = Log
::singleton(
71 'file', $file, 'Database', $conf);
75 if (!is_object(self
::$server)) {
76 self
::$server = Log
::singleton(
77 'file', $file, 'Server', $conf);
82 * Log critical error, and exit.
84 public static function critical($message)
86 IrrecoLog
::$critical->log($message, PEAR_LOG_CRIT
);
91 * PHP error handler for saving errors to Log.
93 public static function phpErrorHandler($code, $message, $file, $line)
95 if ($code > self
::$php_level) return;
97 /* Map the PHP error to a Log priority. */
101 $priority = PEAR_LOG_WARNING
;
106 $priority = PEAR_LOG_NOTICE
;
111 $priority = PEAR_LOG_ERR
;
115 $priority = PEAR_LOG_INFO
;
119 IrrecoLog
::$php->log('[' . $code . '] ' . $message . ' in ' .
120 $file . ' at line ' . $line . '.',
125 * PHP exception handler for saving uncaught exceptions to log.
127 public static function phpExceptionHandler($exception)
129 IrrecoLog
::$exception->log($exception->getMessage(),
134 * PEAR error handler for saving errors to Log.
136 public static function pearErrorHandler($error)
138 $message = $error->getMessage();
140 if (!empty($error->backtrace
[1]['file'])) {
141 $message .= ' (' . $error->backtrace
[1]['file'];
142 if (!empty($error->backtrace
[1]['line'])) {
143 $message .= ' at line ';
144 $message .= $error->backtrace
[1]['line'];
149 $log = IrrecoLog
::$pear;
151 /* Make sure the error code is a valid PEAR error code. */
152 switch ($error->code
) {
157 case PEAR_LOG_WARNING
:
158 case PEAR_LOG_NOTICE
:
161 $code = $error->code
;
165 $message = '[' . $error->code
. '] ' . $message;
166 $code = PEAR_LOG_NOTICE
;
169 $log->log($message, $code);
173 * Set PEAR error reporting level.
175 * @param $level Errors of this level or more signifacant are logged.
177 public static function pearLevel($level)
179 $mask = IrrecoLog
::$database->MAX($level);
181 IrrecoLog
::$critical->setMask($mask);
182 IrrecoLog
::$php->setMask($mask);
183 IrrecoLog
::$exception->setMask($mask);
184 IrrecoLog
::$pear->setMask($mask);
185 IrrecoLog
::$index->setMask($mask);
186 IrrecoLog
::$database->setMask($mask);
187 IrrecoLog
::$server->setMask($mask);
193 * @param $level Errors of this level or more signifacant are logged.
195 public static function phpLevel($level)
197 self
::$php_level = $level;
198 error_reporting($level);