Page MenuHomeIn-Portal Phabricator

D177.diff
No OneTemporary

File Metadata

Created
Sat, Jun 28, 7:16 PM

D177.diff

Index: branches/5.3.x/core/kernel/utility/logger.php
===================================================================
--- branches/5.3.x/core/kernel/utility/logger.php
+++ branches/5.3.x/core/kernel/utility/logger.php
@@ -645,13 +645,22 @@
$errstr = self::expandMessage($exception->getMessage(), !$this->_debugMode);
$this->_logRecord['LogLevel'] = self::LL_CRITICAL;
+ $exception_trace = $exception->getTrace();
+
+ array_unshift($exception_trace, array(
+ 'function' => '',
+ 'file' => $exception->getFile() !== null ? $exception->getFile() : 'n/a',
+ 'line' => $exception->getLine() !== null ? $exception->getLine() : 'n/a',
+ 'args' => array(),
+ ));
+
if ( $this->isLogType(self::LT_DATABASE, $errstr) ) {
list ($errno, $errstr, $sql) = self::parseDatabaseError($errstr);
$this->_logRecord['LogType'] = self::LT_DATABASE;
$this->_logRecord['LogUserData'] = $sql;
- $trace = $this->createTrace($exception->getTrace(), null, $this->_ignoreInTrace);
+ $trace = $this->createTrace($exception_trace, null, $this->_ignoreInTrace);
$this->addSource($trace);
$this->addTrace($trace, 0);
}
@@ -660,7 +669,7 @@
$errno = $exception->getCode();
$this->addSource((string)$exception->getFile(), $exception->getLine());
- $this->addTrace($exception->getTrace(), 0);
+ $this->addTrace($exception_trace, 0);
}
$this->_logRecord['LogCode'] = $errno;
@@ -908,12 +917,50 @@
$errfile = $this->_logRecord['LogSourceFilename'];
$errline = $this->_logRecord['LogSourceFileLine'];
- $result = '<strong>' . $errno . ': </strong>' . "{$errstr} in {$errfile} on line {$errline}";
+ if ( PHP_SAPI === 'cli' ) {
+ $result = sprintf(' [%s] ' . PHP_EOL . ' %s', $errno, $errstr);
+
+ if ( $this->_logRecord['LogBacktrace'] ) {
+ $result .= $this->printBacktrace(unserialize($this->_logRecord['LogBacktrace']));
+ }
+ }
+ else {
+ $result = '<strong>' . $errno . ': </strong>' . "{$errstr} in {$errfile} on line {$errline}";
+ }
return $strip_tags ? strip_tags($result) : $result;
}
/**
+ * Prints backtrace result
+ *
+ * @param array $trace Trace.
+ *
+ * @return string
+ */
+ protected function printBacktrace(array $trace)
+ {
+ if ( !$trace ) {
+ return '';
+ }
+
+ $ret = PHP_EOL . PHP_EOL . PHP_EOL . 'Exception trace:' . PHP_EOL;
+
+ foreach ( $trace as $trace_info ) {
+ $class = isset($trace_info['class']) ? $trace_info['class'] : '';
+ $type = isset($trace_info['type']) ? $trace_info['type'] : '';
+ $function = $trace_info['function'];
+ $args = isset($trace_info['args']) && $trace_info['args'] ? '...' : '';
+ $file = isset($trace_info['file']) ? $trace_info['file'] : 'n/a';
+ $line = isset($trace_info['line']) ? $trace_info['line'] : 'n/a';
+
+ $ret .= sprintf(' %s%s%s(%s) at %s:%s' . PHP_EOL, $class, $type, $function, $args, $file, $line);
+ }
+
+ return $ret;
+ }
+
+ /**
* Saves log to file (e.g. when not possible to save into database)
*
* @param $filename
@@ -1149,7 +1196,15 @@
$errno = $this->_getFatalErrorTitle($errno);
$margin = $this->Application->isAdmin ? '8px' : 'auto';
- echo '<div style="background-color: #FEFFBF; margin: ' . $margin . '; padding: 10px; border: 2px solid red; text-align: center">' . $this->_logger->toString($errno) . '</div>';
+ $error_msg = $this->_logger->toString($errno, PHP_SAPI === 'cli');
+
+ if ( PHP_SAPI === 'cli' ) {
+ echo $error_msg;
+ }
+ else {
+ echo '<div style="background-color: #FEFFBF; margin: ' . $margin . '; padding: 10px; border: 2px solid red; text-align: center">' . $error_msg . '</div>';
+ }
+
exit;
}

Event Timeline