Index: branches/5.2.x/index.php =================================================================== diff -u -N -r16425 -r16426 --- branches/5.2.x/index.php (.../index.php) (revision 16425) +++ branches/5.2.x/index.php (.../index.php) (revision 16426) @@ -1,6 +1,6 @@ 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); } @@ -658,7 +667,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; @@ -906,12 +915,50 @@ $errfile = $this->_logRecord['LogSourceFilename']; $errline = $this->_logRecord['LogSourceFileLine']; - $result = '' . $errno . ': ' . "{$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 = '' . $errno . ': ' . "{$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 @@ -1147,7 +1194,15 @@ $errno = $this->_getFatalErrorTitle($errno); $margin = $this->Application->isAdmin ? '8px' : 'auto'; - echo '
' . $this->_logger->toString($errno) . '
'; + $error_msg = $this->_logger->toString($errno, PHP_SAPI === 'cli'); + + if ( PHP_SAPI === 'cli' ) { + echo $error_msg; + } + else { + echo '
' . $error_msg . '
'; + } + exit; }