public static function displayErrorHelper($err, $alternativeSeparator = false)
 {
     $output = '';
     $separator = $alternativeSeparator ? static::NEWLINE_ALT : static::NEWLINE;
     if ($err['type'] != 'fatal') {
         $output .= static::colorText($err['type'] . ': ' . \Nf\Error\Handler::recursiveArrayToString(static::escape($err['message'])), 'red');
         $output .= $separator;
         $output .= static::colorText($err['file'] . ' (line ' . $err['line'] . ')', 'green', $alternativeSeparator);
         $output .= $separator . '-----' . $separator;
         $output .= implode($separator, self::getFileSample($err['file'], $err['line']));
         $output .= $separator . '-----' . $separator;
         $trace = $err['fullException']->getTrace();
         foreach ($trace as $entry) {
             $output .= self::stackTracePrintEntry($entry);
             if (isset($entry['file']) && isset($entry['line'])) {
                 $output .= '-----' . $separator;
                 $output .= implode($separator, self::getFileSample($entry['file'], $entry['line'], 2));
                 $output .= $separator . '-----' . $separator;
             }
         }
     } else {
         $output .= $err['message'] . $separator;
         $output .= static::preFormatErrorText(0, $alternativeSeparator);
         $output .= self::stackTracePrintEntry($err, 2, $alternativeSeparator);
         $output .= static::preFormatErrorText(1, $alternativeSeparator);
     }
     return $output;
 }
Example #2
-1
 public function log($err)
 {
     $config = Registry::get('config');
     // We need a transport - UDP via port 12201 is standard.
     $transport = new \Gelf\Transport\UdpTransport($config->error->logger->gelf->ip, $config->error->logger->gelf->port, \Gelf\Transport\UdpTransport::CHUNK_SIZE_LAN);
     // While the UDP transport is itself a publisher, we wrap it in a real Publisher for convenience
     // A publisher allows for message validation before transmission, and it calso supports to send messages
     // to multiple backends at once
     $publisher = new \Gelf\Publisher();
     $publisher->addTransport($transport);
     $fullMessage = \Nf\Front\Response\Cli::displayErrorHelper($err);
     // Now we can create custom messages and publish them
     $message = new \Gelf\Message();
     $message->setShortMessage(Handler::recursiveArrayToString($err['message']))->setLevel(\Psr\Log\LogLevel::ERROR)->setFile($err['file'])->setLine($err['line'])->setFullMessage($fullMessage);
     if (php_sapi_name() == 'cli') {
         global $argv;
         $message->setAdditional('url', 'su ' . $_SERVER['LOGNAME'] . ' -c "php ' . Registry::get('applicationPath') . '/html/' . implode(' ', $argv) . '"');
     } else {
         $message->setAdditional('url', 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
     }
     if (isset($config->error->logger->additionals)) {
         foreach ($config->error->logger->additionals as $additionalName => $additionalValue) {
             $message->setAdditional($additionalName, $additionalValue);
         }
     }
     if ($publisher->publish($message)) {
         return true;
     } else {
         return false;
     }
 }