Example #1
0
 /**
  * Log an arbitrary string or Exception.
  *
  * @param $message string|Exception message to log
  * @param $type string optional type of message
  */
 public static function log($message, $type = 'error')
 {
     // Did we get an Exception?
     if ($message instanceof \Exception) {
         // Get a unique string - we can log this, and then display it to the
         // user as a reference number.
         self::$reference .= substr(sha1(time() . __FILE__), 0, 10) . ' ';
         self::$exceptionCount++;
         $message_text = self::$reference . ':: Uncaught ' . get_class($message) . ' - ' . $message->getMessage() . "\n" . $message->getTraceAsString();
     } elseif (is_array($message) || is_object($message)) {
         $message_text = print_r($message, 1);
     } else {
         $message_text = $message;
     }
     // if we're grepping for something specific, make sure this message matches:
     if (isset(static::$grep) && !preg_match(static::$grep, $message_text)) {
         return;
     }
     // If blode is sitting around, send it our message.
     if (class_exists('Event')) {
         Event::err($message_text);
     }
     if (static::$logUserAgent && isset($_SERVER['HTTP_USER_AGENT'])) {
         $message_text .= ' [' . $_SERVER['HTTP_USER_AGENT'] . ']';
     }
     $message_text .= "\n";
     self::$failCount++;
     self::$failText .= $message_text;
     if (isset(self::$logFile)) {
         // Note deliberate error suppression; there's a good chance this
         // write will fail from the command line.
         @file_put_contents(self::$logFile, $message_text, \FILE_APPEND);
     } else {
         error_log($message_text);
     }
 }