Example #1
0
 /**
  * Writes a $line to the log with the given severity
  *
  * @param string  $line     Text to add to the log
  * @param integer $severity Severity level of log message (use constants)
  */
 public function log($line, $severity, $args = NULL)
 {
     if ($this->_severityThreshold >= $severity) {
         $status = $this->_getTimeLine($severity);
         $bt = debug_backtrace();
         $info = array();
         while (isset($bt[0]['class']) && $bt[0]['class'] == 'CAT_Helper_KLogger') {
             $last = array_shift($bt);
         }
         if (count($bt)) {
             $info = array_shift($bt);
         }
         $class = isset($info['class']) ? $info['class'] : NULL;
         $function = isset($info['function']) ? $info['function'] : NULL;
         $file = isset($info['file']) ? basename($info['file']) : NULL;
         $code_line = isset($info['line']) ? $info['line'] : '?' . isset($last['line']) ? '(' . $last['line'] . ')' : '';
         if (substr($line, 0, 1) == '<') {
             self::$spaces--;
         }
         self::$spaces = self::$spaces > 0 ? self::$spaces : 0;
         $line = str_repeat('    ', self::$spaces) . $line;
         if (substr($line, 0, 1) == '>') {
             self::$spaces++;
         }
         $line = "[{$function}()] {$line} [ {$file}:{$code_line} ]";
         $this->writeFreeFormLine("{$status} {$line} \n");
         if ($args) {
             $dump = print_r($args, 1);
             $dump = preg_replace("/\r?\n/", "\n          ", $dump);
             $this->writeFreeFormLine(print_r($dump, 1) . "\n");
         }
     }
 }
Example #2
0
 /**
  * exception handler; allows to remove paths from error messages and show
  * optional stack trace if CAT_Helper_DB::$trace is true
  **/
 public static function exceptionHandler($exception)
 {
     if (CAT_Helper_DB::$exc_trace === true) {
         $traceline = "#%s %s(%s): %s(%s)";
         $msg = "Uncaught exception '%s' with message '%s'<br />" . "<div style=\"font-size:smaller;width:80%%;margin:5px auto;text-align:left;\">" . "in %s:%s<br />Stack trace:<br />%s<br />" . "thrown in %s on line %s</div>";
         $trace = $exception->getTrace();
         foreach ($trace as $key => $stackPoint) {
             $trace[$key]['args'] = array_map('gettype', $trace[$key]['args']);
         }
         // build tracelines
         $result = array();
         foreach ($trace as $key => $stackPoint) {
             $result[] = sprintf($traceline, $key, isset($stackPoint['file']) ? $stackPoint['file'] : '-', isset($stackPoint['line']) ? $stackPoint['line'] : '-', $stackPoint['function'], implode(', ', $stackPoint['args']));
         }
         // trace always ends with {main}
         $result[] = '#' . ++$key . ' {main}';
         // write tracelines into main template
         $msg = sprintf($msg, get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine(), implode("<br />", $result), $exception->getFile(), $exception->getLine());
     } else {
         // template
         $msg = "[DB Exception] %s<br />";
         // filter message
         $message = $exception->getMessage();
         preg_match('~SQLSTATE\\[[^\\]].+?\\]\\s+\\[[^\\]].+?\\]\\s+(.*)~i', $message, $match);
         $msg = sprintf($msg, isset($match[1]) ? $match[1] : $message);
     }
     try {
         $logger = CAT_Helper_KLogger::instance(CAT_PATH . '/temp/logs', 2);
         $logger->logFatal(sprintf('Exception with message [%s] emitted in [%s] line [%s]', $exception->getMessage(), $exception->getFile(), $exception->getLine()));
         $logger->logFatal($msg);
     } catch (Exception $e) {
     }
     // log or echo as you please
     CAT_Object::printFatalError($msg);
 }
Example #3
0
 /**
  * global shutdown handler; allows to log errors that caused a shutdown
  **/
 public static function shutdownHandler()
 {
     $lasterror = error_get_last();
     switch ($lasterror['type']) {
         case E_ERROR:
         case E_CORE_ERROR:
         case E_COMPILE_ERROR:
         case E_USER_ERROR:
         case E_RECOVERABLE_ERROR:
         case E_CORE_WARNING:
         case E_COMPILE_WARNING:
         case E_PARSE:
             $error = "[SHUTDOWN] lvl:" . $lasterror['type'] . " | msg:" . $lasterror['message'] . " | file:" . $lasterror['file'] . " | ln:" . $lasterror['line'];
             $logger = CAT_Helper_KLogger::instance(CAT_PATH . '/temp/logs', 2);
             $logger->logFatal($error);
     }
 }
Example #4
0
 /**
  * Accessor to KLogger class; this makes using the class significant faster!
  *
  * @access public
  * @return object
  *
  **/
 public function log()
 {
     // 8 = OFF
     if ($this->debugLevel < 8) {
         if (!is_object($this->logObj)) {
             if (!CAT_Registry::exists('CAT_PATH', false)) {
                 CAT_Registry::define('CAT_PATH', dirname(__FILE__) . '/../..', 1);
             }
             $debug_dir = CAT_PATH . '/temp/logs' . ($this->debugLevel == 7 ? '/debug_' . get_class($this) : '');
             if (get_class($this) != 'CAT_Helper_Directory') {
                 $debug_dir = CAT_Helper_Directory::sanitizePath($debug_dir);
             }
             if (!file_exists($debug_dir)) {
                 if (get_class($this) != 'CAT_Helper_Directory') {
                     CAT_Helper_Directory::createDirectory($debug_dir, 0777);
                 } else {
                     mkdir($debug_dir, 0777);
                 }
             }
             $this->logObj = CAT_Helper_KLogger::instance($debug_dir, $this->debugLevel);
         }
         return $this->logObj;
     }
     return $this;
 }