/**
  * @param \Exception $e
  * @param string|bool $message
  * @return static
  */
 public function logException(\Exception $e, $message = false)
 {
     $this->stream()->emptyLine();
     $this->stream()->writeLine(str_repeat('*', 32));
     if ($message) {
         $this->stream()->emptyLine();
         $this->stream()->writeLine("" . $message . "");
     }
     $this->stream()->emptyLine();
     $this->stream()->writeLine("Err Message: {$e->getMessage()}");
     $this->stream()->writeLine("At:          {$e->getFile()}");
     $this->stream()->writeLine("Line:        {$e->getLine()}");
     if ($e->getCode() != 0) {
         $this->stream()->writeLine("Code:        " . $e->getLine());
     }
     $this->stream()->writeLine('Stack: ');
     $this->stream()->emptyLine();
     foreach (explode("\n", $e->getTraceAsString()) as $line) {
         $line = str_replace("\r", '', $line);
         $this->stream()->writeLine("    {$line}");
     }
     $this->stream()->emptyLine();
     $this->stream()->writeLine(str_repeat('*', 32));
     $this->stream()->emptyLine();
     return $this;
 }
 /**
  * Get a backtrace for an exception.
  *
  * Optionally limit the number of rows to include with $count, and exclude
  * Psy from the trace.
  *
  * @param \Exception $e          The exception with a backtrace.
  * @param int        $count      (default: PHP_INT_MAX)
  * @param bool       $includePsy (default: true)
  *
  * @return array Formatted stacktrace lines.
  */
 protected function getBacktrace(\Exception $e, $count = null, $includePsy = true)
 {
     if ($cwd = getcwd()) {
         $cwd = rtrim($cwd, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
     }
     if ($count === null) {
         $count = PHP_INT_MAX;
     }
     $lines = array();
     $trace = $e->getTrace();
     array_unshift($trace, array('function' => '', 'file' => $e->getFile() !== null ? $e->getFile() : 'n/a', 'line' => $e->getLine() !== null ? $e->getLine() : 'n/a', 'args' => array()));
     if (!$includePsy) {
         for ($i = count($trace) - 1; $i >= 0; $i--) {
             $thing = isset($trace[$i]['class']) ? $trace[$i]['class'] : $trace[$i]['function'];
             if (preg_match('/\\\\?Psy\\\\/', $thing)) {
                 $trace = array_slice($trace, $i + 1);
                 break;
             }
         }
     }
     for ($i = 0, $count = min($count, count($trace)); $i < $count; $i++) {
         $class = isset($trace[$i]['class']) ? $trace[$i]['class'] : '';
         $type = isset($trace[$i]['type']) ? $trace[$i]['type'] : '';
         $function = $trace[$i]['function'];
         $file = isset($trace[$i]['file']) ? $this->replaceCwd($cwd, $trace[$i]['file']) : 'n/a';
         $line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a';
         $lines[] = sprintf(' <class>%s</class>%s%s() at <info>%s:%s</info>', OutputFormatter::escape($class), OutputFormatter::escape($type), OutputFormatter::escape($function), OutputFormatter::escape($file), OutputFormatter::escape($line));
     }
     return $lines;
 }
Example #3
0
 /**
  * @param \Exception $objEx
  */
 public function push(\Exception $objEx)
 {
     $this->errorStackTraces[] = ['code' => $objEx->getCode(), 'file' => $objEx->getFile(), 'line' => $objEx->getLine(), 'msg' => $objEx->getMessage(), 'string' => $objEx->getTraceAsString()];
     if ($this->versionType === 'dev') {
         print sprintf('Exception in %s, line %s with message %s', $objEx->getFile(), $objEx->getLine(), $objEx->getMessage());
     }
 }
Example #4
0
 /**
  * Get a backtrace for an exception.
  *
  * Optionally limit the number of rows to include with $count, and exclude
  * Psy from the trace.
  *
  * @param \Exception $e          The exception with a backtrace.
  * @param int        $count      (default: PHP_INT_MAX)
  * @param bool       $includePsy (default: true)
  *
  * @return array Formatted stacktrace lines.
  */
 protected function getBacktrace(\Exception $e, $count = null, $includePsy = true)
 {
     if ($count === null) {
         $count = PHP_INT_MAX;
     }
     $lines = array();
     $trace = $e->getTrace();
     array_unshift($trace, array('function' => '', 'file' => $e->getFile() != null ? $e->getFile() : 'n/a', 'line' => $e->getLine() != null ? $e->getLine() : 'n/a', 'args' => array()));
     if (!$includePsy) {
         for ($i = count($trace) - 1; $i >= 0; $i--) {
             $thing = isset($trace[$i]['class']) ? $trace[$i]['class'] : $trace[$i]['function'];
             if (preg_match('/\\\\?Psy\\\\/', $thing)) {
                 $trace = array_slice($trace, $i + 1);
                 break;
             }
         }
     }
     for ($i = 0, $count = min($count, count($trace)); $i < $count; $i++) {
         $class = isset($trace[$i]['class']) ? $trace[$i]['class'] : '';
         $type = isset($trace[$i]['type']) ? $trace[$i]['type'] : '';
         $function = $trace[$i]['function'];
         $file = isset($trace[$i]['file']) ? $trace[$i]['file'] : 'n/a';
         $line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a';
         $lines[] = sprintf(' %s%s%s() at <info>%s:%s</info>', $class, $type, $function, $file, $line);
     }
     return $lines;
 }
Example #5
0
 /**
  * @param \Exception $e
  * @param string|bool $message
  * @return static
  */
 public function logException(\Exception $e, $message = false)
 {
     $this->stream()->emptyLine();
     $this->stream()->write('<hr>');
     if ($message) {
         $this->stream()->emptyLine();
         $this->stream()->writeLine($message);
     }
     $this->stream()->emptyLine();
     $this->stream()->writeLine("Err Message: {$e->getMessage()}");
     $this->stream()->writeLine("At: {$e->getFile()}");
     $this->stream()->writeLine("Line: {$e->getLine()}");
     if ($e->getCode() != 0) {
         $this->stream()->writeLine("Code: {$e->getLine()}");
     }
     $this->stream()->writeLine('Stack: ');
     $this->stream()->emptyLine();
     $this->stream()->writeLine("<ol>");
     foreach (explode("\n", $e->getTraceAsString()) as $line) {
         $line = str_replace("\r", '', $line);
         $this->stream()->writeLine("<li>{$line}</li>");
     }
     $this->stream()->writeLine("</ol>");
     $this->stream()->emptyLine();
     $this->stream()->write('<hr>');
     $this->stream()->emptyLine();
     return $this;
 }
Example #6
0
 /**
  * If detailed errors are enabled, just format the exception into
  * a simple error message and display it.
  *
  * @param \Exception $exception
  * @param boolean    $isCli
  *
  * @return string
  */
 public static function format(\Exception $exception, $isCli = false)
 {
     if ($isCli === true) {
         return "+++ Untreated Exception +++" . PHP_EOL . "Message: " . $exception->getMessage() . PHP_EOL . "Location: " . $exception->getFile() . " on line " . $exception->getLine() . PHP_EOL . "Stack Trace: " . PHP_EOL . $exception->getTraceAsString() . PHP_EOL;
     }
     return "<html>\n    <head>\n      <style>\n        pre { display: block;\n            padding: 8.5px;\n            margin: 0 0 9px;\n            line-height: 18px;\n            word-break: break-all;\n            word-wrap: break-word;\n            white-space: pre;\n            white-space: pre-wrap;\n            border: 1px solid #ccc;\n            border: 1px solid rgba(0, 0, 0, 0.15);\n            -webkit-border-radius: 4px;\n            -moz-border-radius: 4px;\n            border-radius: 6px;\n            color: chartreuse;\n            background-color: black;\n        }\n      </style>\n    </head>\n      <h2>Untreated Exception</h2>\n      <h3>Message:</h3>\n      <pre>" . $exception->getMessage() . "</pre>\n      <h3>Location:</h3>\n      <pre>" . $exception->getFile() . " on line " . $exception->getLine() . "</pre>\n      <h3>Stack Trace:</h3>\n      <pre>" . $exception->getTraceAsString() . "</pre></html>";
 }
Example #7
0
 /**
  * Filters stack frames from PHPUnit classes.
  *
  * @param  Exception $e
  * @param  boolean   $filterTests
  * @param  boolean   $asString
  * @return string
  */
 public static function getFilteredStacktrace(Exception $e, $filterTests = TRUE, $asString = TRUE)
 {
     if ($asString === TRUE) {
         $filteredStacktrace = '';
     } else {
         $filteredStacktrace = array();
     }
     $groups = array('DEFAULT');
     if (!defined('PHPUNIT_TESTSUITE')) {
         $groups[] = 'PHPUNIT';
     }
     if ($filterTests) {
         $groups[] = 'TESTS';
     }
     $eTrace = $e->getTrace();
     if (!self::frameExists($eTrace, $e->getFile(), $e->getLine())) {
         array_unshift($eTrace, array('file' => $e->getFile(), 'line' => $e->getLine()));
     }
     foreach ($eTrace as $frame) {
         if (isset($frame['file']) && is_file($frame['file']) && !PHP_CodeCoverage::getInstance()->filter()->isFiltered($frame['file'], $groups, TRUE)) {
             if ($asString === TRUE) {
                 $filteredStacktrace .= sprintf("%s:%s\n", $frame['file'], isset($frame['line']) ? $frame['line'] : '?');
             } else {
                 $filteredStacktrace[] = $frame;
             }
         }
     }
     return $filteredStacktrace;
 }
Example #8
0
 /**
  * Filters stack frames from PHPUnit classes.
  *
  * @param  Exception $e
  * @param  boolean   $asString
  * @return string
  */
 public static function getFilteredStacktrace(Exception $e, $asString = TRUE)
 {
     if (!defined('PHPUNIT_TESTSUITE')) {
         $blacklist = PHPUnit_Util_GlobalState::phpunitFiles();
     } else {
         $blacklist = array();
     }
     if ($asString === TRUE) {
         $filteredStacktrace = '';
     } else {
         $filteredStacktrace = array();
     }
     if ($e instanceof PHPUnit_Framework_SyntheticError) {
         $eTrace = $e->getSyntheticTrace();
     } else {
         $eTrace = $e->getTrace();
     }
     if (!self::frameExists($eTrace, $e->getFile(), $e->getLine())) {
         array_unshift($eTrace, array('file' => $e->getFile(), 'line' => $e->getLine()));
     }
     foreach ($eTrace as $frame) {
         if (isset($frame['file']) && is_file($frame['file']) && !isset($blacklist[$frame['file']])) {
             if ($asString === TRUE) {
                 $filteredStacktrace .= sprintf("%s:%s\n", $frame['file'], isset($frame['line']) ? $frame['line'] : '?');
             } else {
                 $filteredStacktrace[] = $frame;
             }
         }
     }
     return $filteredStacktrace;
 }
 /**
  * If detailed errors are enabled, just format the exception into
  * a simple error message and display it.
  *
  * @param \Exception $exception
  *
  * @return string
  */
 public static function format(\Exception $exception)
 {
     if (Sapi::isCli()) {
         return "+++ Untreated Exception +++" . PHP_EOL . "Message: " . $exception->getMessage() . PHP_EOL . "Location: " . $exception->getFile() . " on line " . $exception->getLine() . PHP_EOL . "Stack Trace: " . PHP_EOL . $exception->getTraceAsString() . PHP_EOL;
     }
     return "<html><h2>Untreated Exception</h2>\n      <h3>Message:</h3>\n      <pre>" . $exception->getMessage() . "</pre>\n      <h3>Location:</h3>\n      <pre>" . $exception->getFile() . " on line " . $exception->getLine() . "</pre>\n      <h3>Stack Trace:</h3>\n      <pre>" . $exception->getTraceAsString() . "</pre></html>";
 }
Example #10
0
 /**
  * Show exception screen
  *
  * @param \Exception $exception
  */
 public function showException(\Exception $exception)
 {
     @ob_end_clean();
     $msg = sprintf("%s\nFile: %s\nLine: %d\nTrace:\n%s", $exception->getMessage(), $exception->getFile(), $exception->getLine(), $exception->getTraceAsString());
     \Kalibri::logger()->add(Logger::L_EXCEPTION, $msg);
     $viewName = \Kalibri::config()->get('error.view.exception');
     if ($viewName) {
         $view = new \Kalibri\View($viewName);
         $view->ex = $exception;
         $str = '';
         $file = \fopen($exception->getFile(), 'r');
         for ($i = 0; $i < $exception->getLine() - 16; $i++) {
             \fgets($file);
         }
         for ($i = 0; $i < 20; $i++) {
             $str .= \fgets($file);
         }
         $view->code = Highlight::php($str, true, 1, $exception->getLine());
         if ($view->isExists()) {
             $view->render();
         } else {
             // Fallback to show any message in case if exception view not found or not set
             echo "<h1>Exception</h1><p>{$exception->getMessage()}</p>";
         }
     }
     exit;
 }
Example #11
0
 /**
  * Function must be public to call on caused exceptions
  * 
  * @param  array
  * @return string
  */
 function getCauseMessage(&$causes)
 {
     $trace = $this->getTrace();
     $cause = array('class' => get_class($this), 'message' => $this->getMessage(), 'file' => 'unknown', 'line' => 'unknown');
     if (isset($trace[0])) {
         if (isset($trace[0]['file'])) {
             $cause['file'] = $trace[0]['file'];
             $cause['line'] = $trace[0]['line'];
         }
     }
     $causes[] = $cause;
     if ($this->cause instanceof Exception) {
         $this->cause->getCauseMessage($causes);
     } elseif ($this->cause instanceof Exception) {
         $causes[] = array('class' => get_class($this->cause), 'message' => $this->cause->getMessage(), 'file' => $this->cause->getFile(), 'line' => $this->cause->getLine());
     }
     if (is_array($this->cause)) {
         foreach ($this->cause as $cause) {
             if ($cause instanceof Exception || $cause instanceof Exception) {
                 $cause->getCauseMessage($causes);
             } elseif ($cause instanceof Exception) {
                 $causes[] = array('class' => get_class($cause), 'message' => $cause->getMessage(), 'file' => $cause->getFile(), 'line' => $cause->getLine());
             } elseif (is_array($cause) && isset($cause['message'])) {
                 // PEAR_ErrorStack warning
                 $causes[] = array('class' => $cause['package'], 'message' => $cause['message'], 'file' => isset($cause['context']['file']) ? $cause['context']['file'] : 'unknown', 'line' => isset($cause['context']['line']) ? $cause['context']['line'] : 'unknown');
             } else {
                 $causes[] = array('class' => null, 'message' => $cause, 'file' => null, 'line' => null);
             }
         }
     }
 }
Example #12
0
/**
 * @param \Exception $e
 * @return bool
 */
function exceptionHandler(\Exception $e)
{
    echo '<h1>Error</h1><p>Sorry, the script died with a exception</p>';
    echo $e->getMessage() . ' in <br>' . $e->getFile() . ': <br>' . $e->getLine(), ' : <br>', __FUNCTION__, ' : <br>', $e->getTraceAsString();
    log::error($e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine() . "<br>\n", "Code: " . $e->getCode(), $e->getTrace());
    mail(ADMIN_MAIL, '[GitReminder] System got locked', $e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine() . "\n\n" . "Funktion -> " . __FUNCTION__ . $e->getTraceAsString() . "\n\n" . "Code: " . $e->getCode());
    @trigger_error('', E_USER_ERROR);
}
 public function handleException(Exception $exception)
 {
     $msg = "Uncaught Exception: " . $exception->getMessage() . "\n";
     $msg .= $exception->getMessage() . "\n";
     $msg .= 'Line: ' . $exception->getLine() . " in " . $exception->getFile();
     $msg .= "\n\nTrace Summary:\n" . self::traceFormat($exception->getTrace());
     if (ERROR_DISPLAY_MODE == 'html') {
         $msg .= "\nFull Trace: \n" . print_r($exception->getTrace(), 1);
     }
     $this->show($msg, $exception->getFile(), $exception->getLine(), $exception->getCode(), 'E_WARNING');
 }
 /**
  * @description Build message
  *
  * @return string
  */
 public function exceptionMessage()
 {
     $msg = '';
     if ($this->exception->getCode()) {
         $msg .= "Exception code: " . $this->exception->getCode() . PHP_EOL;
     }
     $msg .= $this->exception->getMessage() . PHP_EOL;
     $msg .= "At file: " . $this->exception->getFile();
     $msg .= ": " . $this->exception->getLine() . PHP_EOL;
     $msg .= "Trace: " . PHP_EOL . $this->exception->getTraceAsString();
     return $msg;
 }
Example #15
0
 /**
  * Logs the original exception message.
  *
  * Provided as a manual override over the default `WP_DEBUG` dependent behaviour.
  *
  * @see Tribe__Exception::handle()
  *
  * @return bool  `true` if the message was logged, `false` otherwise.
  */
 private function log_original_exception_message()
 {
     if (!class_exists('Tribe__Log')) {
         return false;
     }
     $logger = new Tribe__Log();
     $message = $this->original_exception->getMessage();
     $log_type = $this->get_log_type_for_exception_code($this->original_exception->getCode());
     $src = $this->original_exception->getFile() . ':' . $this->original_exception->getLine();
     $logger->log($message, $log_type, $src);
     return true;
 }
Example #16
0
 /**
  * Return an error into an HTTP or JSON data array.
  *
  * @param string $title
  * @return array
  */
 public function error($title = null)
 {
     if ($title == null) {
         $title = $this->debug ? 'The application could not run because of the following error:' : 'A website error has occurred. Sorry for the temporary inconvenience.';
     }
     $type = $this->request->getHeader('Content-Type');
     $mesg = $this->exception->getMessage();
     $file = $this->exception->getFile();
     $line = $this->exception->getLine();
     $code = $this->exception->getCode();
     $statusCode = method_exists($this->exception, 'getStatusCode') ? $this->exception->getStatusCode() : null;
     // Check status code is null
     if ($statusCode == null) {
         $statusCode = $code >= 100 && $code <= 500 ? $code : 400;
     }
     $this->response->withStatus($statusCode);
     // Check logger exist
     if ($this->logger !== null) {
         // Send error to log
         $this->logger->addError($this->exception->getMessage());
     }
     $this->isJson = isset($type[0]) && $type[0] == 'application/json';
     // Check content-type is application/json
     if ($this->isJson) {
         // Define content-type to json
         $this->response->withHeader('Content-Type', 'application/json');
         $error = ['status' => 'error', 'status_code' => $statusCode, 'error' => $title, 'details' => []];
         // Check debug
         if ($this->debug) {
             $error['details'] = ['message' => $mesg, 'file' => $file, 'line' => $line, 'code' => $code];
         }
         return $error;
     }
     // Define content-type to html
     $this->response->withHeader('Content-Type', 'text/html');
     $message = sprintf('<span>%s</span>', htmlentities($mesg));
     $error = ['type' => get_class($this->exception), $error['status_code'] = $statusCode, 'message' => $message];
     // Check debug
     if ($this->debug) {
         $trace = $this->exception->getTraceAsString();
         $trace = sprintf('<pre>%s</pre>', htmlentities($trace));
         $error['file'] = $file;
         $error['line'] = $line;
         $error['code'] = $code;
         $error['trace'] = $trace;
     }
     $error['debug'] = $this->debug;
     $error['title'] = $title;
     return $error;
 }
 /**
  * {@inheritdoc}
  */
 protected function render()
 {
     global $argv;
     $message = $this->exception->getMessage();
     $file = $this->exception->getFile();
     $line = $this->exception->getLine();
     $code = $this->exception->getCode();
     $command = implode(" ", $argv);
     $this->printText("<<6>>{$message}\n\n");
     $this->printText("<<3>>File    : <<0>>{$file}\n");
     $this->printText("<<3>>Line    : <<0>>{$line}\n");
     $this->printText("<<3>>Code    : <<0>>{$code}\n");
     $this->printText("<<3>>Command : <<0>>{$command}\n");
 }
 /**
  * Displays a human readable, partly beautified version of the given exception
  * and stops the application, return a non-zero exit code.
  *
  * @static
  * @param \Exception $exception
  * @return void
  */
 public static function writeResponseAndExit(\Exception $exception)
 {
     $response = new Response();
     $exceptionMessage = '';
     $exceptionReference = "\n<b>More Information</b>\n";
     $exceptionReference .= "  Exception code      #" . $exception->getCode() . "\n";
     $exceptionReference .= "  File                " . $exception->getFile() . ($exception->getLine() ? ' line ' . $exception->getLine() : '') . "\n";
     $exceptionReference .= $exception instanceof \TYPO3\Flow\Exception ? "  Exception reference #" . $exception->getReferenceCode() . "\n" : '';
     foreach (explode(chr(10), wordwrap($exception->getMessage(), 73)) as $messageLine) {
         $exceptionMessage .= "  {$messageLine}\n";
     }
     $response->setContent(sprintf("<b>Uncaught Exception</b>\n%s%s\n", $exceptionMessage, $exceptionReference));
     $response->send();
     exit(1);
 }
/**
 * Vangt alle onopgevangen exception op
 *
 * @param Exception $exception de exception
 */
function exception_handler($exception)
{
    $error = "<em>" . $exception->getMessage() . "</em><br/>(line " . $exception->getLine() . " in " . $exception->getFile() . ")";
    try {
        $user = "";
        if (isset($_SESSION['userid'])) {
            $user = new User($_SESSION['userid']);
            $user = $user->getGebruikersnaam();
        }
        new Error("", $exception->getMessage(), $exception->getFile(), $exception->getLine(), $user);
    } catch (Exception $e) {
        //doe niets anders is er een oneindige error lus :(
    }
    showError($error);
}
Example #20
0
function displayExceptionObject(Exception $e)
{
    echo "\$e = >{$e}<\n";
    // calls __toString
    echo "getMessage:       >" . $e->getMessage() . "<\n";
    echo "getCode:          >" . $e->getCode() . "<\n";
    echo "getPrevious:      >" . $e->getPrevious() . "<\n";
    echo "getFile:          >" . $e->getFile() . "<\n";
    echo "getLine:          >" . $e->getLine() . "<\n";
    echo "getTraceAsString: >" . $e->getTraceAsString() . "<\n";
    $traceInfo = $e->getTrace();
    var_dump($traceInfo);
    echo "Trace Info:" . (count($traceInfo) == 0 ? " none\n" : "\n");
    foreach ($traceInfo as $traceInfoKey => $traceLevel) {
        echo "Key[{$traceInfoKey}]:\n";
        foreach ($traceLevel as $levelKey => $levelVal) {
            if ($levelKey != "args") {
                echo "  Key[{$levelKey}] => >{$levelVal}<\n";
            } else {
                echo "  Key[{$levelKey}]:\n";
                foreach ($levelVal as $argKey => $argVal) {
                    echo "    Key[{$argKey}] => >{$argVal}<\n";
                }
            }
        }
    }
}
Example #21
0
 /**
  * new exception
  * @param  Exception $exception
  * @param  boolean   $printError show error or not
  * @param  boolean   $clear       clear the errorlog
  * @param  string    $errorFile  file to save to
  */
 public static function newMessage(\Exception $exception)
 {
     $message = $exception->getMessage();
     $code = $exception->getCode();
     $file = $exception->getFile();
     $line = $exception->getLine();
     $trace = $exception->getTraceAsString();
     $date = date('Y-m-d H:i:s');
     $logMessage = "<h3>Exception information:</h3>\n\n           <p><strong>Date:</strong> {$date}</p>\n\n           <p><strong>Message:</strong> {$message}</p>\n\n           <p><strong>Code:</strong> {$code}</p>\n\n           <p><strong>File:</strong> {$file}</p>\n\n           <p><strong>Line:</strong> {$line}</p>\n\n           <h3>Stack trace:</h3>\n\n           <pre>{$trace}</pre>\n\n           <hr />\n";
     if (is_file(self::$errorFile) === false) {
         file_put_contents(self::$errorFile, '');
     }
     if (self::$clear) {
         $f = fopen(self::$errorFile, "r+");
         if ($f !== false) {
             ftruncate($f, 0);
             fclose($f);
         }
         $content = null;
     } else {
         $content = file_get_contents(self::$errorFile);
     }
     file_put_contents(self::$errorFile, $logMessage . $content);
     //send email
     if (MAIL_ERROR === true) {
         self::sendEmail($logMessage);
     }
 }
Example #22
0
 public static function gerarLogException(\Exception $ex)
 {
     $msg = " - " . $ex->getMessage();
     $msg .= " [Arquivo: " . $ex->getFile();
     $msg .= " - Linha: " . $ex->getLine() . " ]";
     return $msg;
 }
Example #23
0
 public static function log_writer(\Exception $exception, $clear = false, $error_file = 'ex_log.html')
 {
     $message = $exception->getMessage();
     $code = $exception->getCode();
     $file = $exception->getFile();
     $line = $exception->getLine();
     $trace = $exception->getTraceAsString();
     $date = date('M d, Y h:iA');
     $log_message = "<h3>Exception information:</h3>\n\t\t<p>\n\t\t<strong>Date:</strong> {$date}\n\t\t</p>\n\n\t\t<p>\n\t\t<strong>Message:</strong> {$message}\n\t\t</p>\n\t\t\t\n\t\t<p>\n\t\t<strong>Code:</strong> {$code}\n\t\t</p>\n\n\t\t<p>\n\t\t<strong>File:</strong> {$file}\n\t\t</p>\n\n\t\t<p>\n\t\t<strong>Line:</strong> {$line}\n\t\t</p>\n\n\t\t<h3>Stack trace:</h3>\n\t\t<pre>{$trace}</pre>\n\t\t\n\t\t<h3>Request information:</h3>\n\t\t<pre>";
     foreach ($_REQUEST as $key => $value) {
         $log_message .= "<strong>{$key}</strong>: {$value}<br/>";
     }
     $log_message .= "</pre>";
     $log_message .= "<h3>Server information:</h3>\n\t\t<pre>";
     foreach ($_SERVER as $key => $value) {
         $log_message .= "<strong>{$key}</strong>: {$value}<br/>";
     }
     $log_message .= "</pre>\n\t\t<br />\n\t\t<hr /><br /><br />";
     if (is_file($error_file) === false) {
         file_put_contents($error_file, '');
     }
     if ($clear) {
         $content = '';
     } else {
         $content = file_get_contents($error_file);
     }
     file_put_contents($error_file, $log_message . $content);
 }
 public function getHtml()
 {
     $html = '<div style="padding:20px;border-radius:20px;background:#EEE;text-align:center;border:1px solid #BBB;height:50px;font-family: monospace;">';
     $html .= '    <h1 style="padding:0;margin:0 0 -10px 0;font-size:20px;">Error: ' . parent::getMessage() . '</h1>';
     $html .= '    <p style="font-size: smaller">In ' . parent::getFile() . ' In ' . parent::getLine() . '</p>';
     $html .= '</div>';
     $html .= '<br/>';
     $html .= '<div style="padding: 20px 25px 30px 25px;border-radius:20px;background:#FFF;text-align:left;border:1px solid #BBB;font-family: monospace;">';
     $html .= '    <h1 style="padding:0;margin:0;font-size: 20px;">Stack Trace</h1>';
     $html .= '    <ul>';
     foreach (parent::getTrace() as $key => $trace) {
         $args = [];
         foreach ($trace['args'] as $arg) {
             if (empty($args)) {
                 $args[] = '\'\'';
             } else {
                 $args[] = '\'' . $arg . '\'';
             }
         }
         $html .= '        <li style="list-style: none;clear: both;">';
         $html .= '            <div style="float:left;margin-right: 10px;color: #9A9A9A;background-color: rgba(232, 232, 232, 0.29);width: 40px;margin-left: -40px;margin-right: 40px;text-align: right;">' . ($key + 1) . '.</div>';
         $html .= '            <div style="float:left;margin-right: 10px;">' . $trace['file'] . '(' . $trace['line'] . ')</div>';
         $html .= '            <div style="float:left">' . $trace['class'] . $trace['type'] . 'setPassword(' . implode(', ', $args) . ')</div>';
         $html .= '        </li>';
     }
     $html .= '     </ul>';
     $html .= '</div>';
     return $html;
 }
 /**
  * Render response body
  * @param array $env
  * @param Exception $exception
  * @return string
  */
 protected function renderBody(&$env, $exception)
 {
     $title = 'Slim Application Error';
     $code = $exception->getCode();
     $message = $exception->getMessage();
     $file = $exception->getFile();
     $line = $exception->getLine();
     $trace = $exception->getTraceAsString();
     $html = sprintf('<h1>%s</h1>', $title);
     $html .= '<p>The application could not run because of the following error:</p>';
     $html .= '<h2>Details</h2>';
     if ($code) {
         $html .= sprintf('<div><strong>Code:</strong> %s</div>', $code);
     }
     if ($message) {
         $html .= sprintf('<div><strong>Message:</strong> %s</div>', $message);
     }
     if ($file) {
         $html .= sprintf('<div><strong>File:</strong> %s</div>', $file);
     }
     if ($line) {
         $html .= sprintf('<div><strong>Line:</strong> %s</div>', $line);
     }
     if ($trace) {
         $html .= '<h2>Trace</h2>';
         $html .= sprintf('<pre>%s</pre>', $trace);
     }
     return sprintf("<html><head><title>%s</title><style>body{margin:0;padding:30px;font:12px/1.5 Helvetica,Arial,Verdana,sans-serif;}h1{margin:0;font-size:48px;font-weight:normal;line-height:48px;}strong{display:inline-block;width:65px;}</style></head><body>%s</body></html>", $title, $html);
 }
Example #26
0
 /**
  * @param \Exception $e
  * @param bool $terminate
  */
 public function exception(\Exception $e, $terminate = true)
 {
     $html_message = '';
     $id = hash('md4', $e->getMessage() . $e->getFile() . $e->getLine());
     if (!$e instanceof \ErrorException) {
         $html_message = '<strong>- Uncaught exception: </strong> ' . get_class($e) . "<br />\n";
     }
     $html_message .= '<strong>- Message:</strong> ' . $e->getMessage();
     if ($this->mode == 'development') {
         $html_message .= "<br />\n<strong>- File:</strong> " . $e->getFile() . "<br />\n<strong>- Line:</strong> " . $e->getLine() . "<br />\n<strong>- Code:</strong> " . $e->getCode();
     }
     $html_message .= "<br />\n<strong>- ID:</strong> {$id}";
     $log_body = trim(strip_tags($html_message));
     // If we're in production/test the html message will not
     // contain info about the file where the error appeared
     // therefor we add it to error log here
     if ($this->mode != 'development') {
         $log_body .= "\n- File: " . $e->getFile() . "\n- Line: " . $e->getLine() . "\n- Code: " . $e->getCode();
     }
     $log_message = '### Error ' . (empty($_SERVER['REQUEST_URI']) ? '' : $_SERVER['REQUEST_URI']) . (empty($_SERVER['REQUEST_METHOD']) ? '' : ' (' . $_SERVER['REQUEST_METHOD'] . ')') . (empty($_SERVER['REMOTE_ADDR']) ? '' : ' ' . $_SERVER['REMOTE_ADDR']) . "\n" . $log_body . "\n" . $e->getTraceAsString();
     if ($this->mode == 'development') {
         $html_message .= "\n<p>" . nl2br($e->getTraceAsString()) . "</p>\n";
     } else {
         $html_message .= "\n<p><em>Stack trace and full error message available in the error log</em></p>\n";
     }
     $html_message = '<h2>PHP Error</h2>' . $html_message;
     error_log($log_message);
     if ($terminate) {
         if (!headers_sent()) {
             header('HTTP/1.1 500 Internal Server Error');
         }
         echo $html_message;
         die;
     }
 }
Example #27
0
 public function logException(Exception $exception, $order_id, $type, $line_nuber = '')
 {
     $message = $exception->getMessage();
     $code = $exception->getCode();
     $file = $exception->getFile();
     $line = $exception->getLine();
     $trace = $exception->getTraceAsString();
     $date = date('M d, Y h:iA');
     if ($type == 'order') {
         $log_message = "<p><strong>Order Id:</strong> {$order_id}\r\n\t\t    <p><strong>Error Message:</strong> {$message}</p>\r\n            <p><strong>Line Number:</strong> {$line_nuber}</p>";
     } else {
         if ($type == 'invoice') {
             $log_message = "<p><strong>Invoice Error : </strong></p>\r\n\t\t    <p><strong>Order Id:</strong> {$order_id}</p>\r\n            <p><strong>Error Message:</strong> {$message}</p>";
         } else {
             if ($type == 'shipment') {
                 $log_message = "<p><strong>Shipment Error : </strong></p>\r\n\t\t    <p><strong>Order Id:</strong> {$order_id}</p>\r\n            <p><strong>Error Message:</strong> {$message}</p>";
             } else {
                 if ($type == 'creditmemo') {
                     $log_message = "<p><strong>Creditmemo Error : </strong></p>\r\n\t\t    <p><strong>Order Id:</strong> {$order_id}</p>\r\n            <p><strong>Error Message:</strong> {$message}</p>";
                 }
             }
         }
     }
     if (is_file($this->error_file) === false) {
         file_put_contents($this->error_file, '');
     }
     $content = file_get_contents($this->error_file);
     file_put_contents($this->error_file, $content . $log_message);
 }
Example #28
0
/**
 * Returns an error trace
 * 
 * @param Exception $e
 * @return string
 */
function KickstartErrorTrace($e)
{
    $strTrace = '#0: ' . $e->getMessage() . '; File: ' . $e->getFile() . '; Line: ' . $e->getLine() . "\n";
    $i = 1;
    foreach ($e->getTrace() as $v) {
        if (!(isset($v['function']) && $v['function'] == 'errorHandle')) {
            if (isset($v['class'])) {
                $strTrace .= "#{$i}: " . $v['class'] . $v['type'] . $v['function'] . '(';
            } elseif (isset($v['function'])) {
                $strTrace .= "#{$i}: " . $v['function'] . '(';
            } else {
                $strTrace .= "#{$i}: ";
            }
            if (isset($v['args']) && isset($v['function'])) {
                $parts = array();
                foreach ($v['args'] as $arg) {
                    $parts[] = KickstartErrorArg($arg);
                }
                $strTrace .= implode(',', $parts) . ') ';
            }
            if (isset($v['file']) && isset($v['line'])) {
                $strTrace .= '; File: ' . $v['file'] . '; Line: ' . $v['line'] . "\n";
            }
            $i++;
        }
    }
    return $strTrace;
}
Example #29
0
 public static function handle_exception(Exception $e)
 {
     echo "<div class='error'>{Exception handler}" . PHP_EOL . "[" . $e->getCode() . "] " . $e->getMessage() . "<br />" . PHP_EOL;
     echo "Line [" . $e->getLine() . "] in file [" . $e->getFile() . "]<br />" . PHP_EOL . $e->getTraceAsString() . "<br />" . PHP_EOL;
     echo "</div>" . PHP_EOL;
     return true;
 }
 /**
  * Обработчик исключений
  * @param Exception $exeption Исключение
  */
 public function exceptionHandler(Exception $exeption)
 {
     $message = $exeption->getMessage();
     $file = $exeption->getFile();
     $line = $exeption->getLine();
     $this->console("Exception: '{$message}' in file {$file}:{$line}");
 }