/** * @param \ErrorException $exception * * @return bool */ protected function handleErrorException(\ErrorException $exception) { switch ($exception->getSeverity()) { case E_ERROR: case E_RECOVERABLE_ERROR: case E_CORE_ERROR: case E_COMPILE_ERROR: case E_USER_ERROR: case E_PARSE: $this->logger->error($this->buildLogMessage($exception)); break; case E_WARNING: case E_USER_WARNING: case E_CORE_WARNING: case E_COMPILE_WARNING: $this->logger->warning($this->buildLogMessage($exception)); break; case E_NOTICE: case E_USER_NOTICE: $this->logger->notice($this->buildLogMessage($exception)); break; case E_STRICT: case E_DEPRECATED: case E_USER_DEPRECATED: $this->logger->info($this->buildLogMessage($exception)); break; } return true; }
public function handleErrors(\ErrorException $e) { $severity = $this->determineSeverityTextValue($e->getSeverity()); $type = 'Error (' . $severity . ')'; $message = $e->getMessage(); $file = $e->getFile(); $line = $e->getLine(); return $this->getHtml($type, $message, $file, $line); }
public function handleErrors(\ErrorException $e) { $severity = $this->determineSeverityTextValue($e->getSeverity()); $message = $e->getMessage(); $file = $e->getFile(); $line = $e->getLine(); $error = ['message' => $message, 'severity' => $severity, 'file' => $file, 'line' => $line]; return $error; }
public function handleErrors(\ErrorException $e) { $errorString = "<strong>%s</strong>: %s in <strong>%s</strong> on line <strong>%d</strong>"; $severity = $this->determineSeverityTextValue($e->getSeverity()); $error = $e->getMessage(); $file = $e->getFile(); $line = $e->getLine(); $error = sprintf($errorString, $severity, $error, $file, $line); return $this->getTable($error); }
public function handleErrors(\ErrorException $e) { $errorString = "%s%s in %s on line %d\n"; $severity = $this->determineSeverityTextValue($e->getSeverity()); // Let's calculate the length of the box, and set the box border. $dashes = "\n+" . str_repeat('-', strlen($severity) + 2) . "+\n"; $severity = $dashes . '| ' . strtoupper($severity) . " |" . $dashes; // Okay, now let's prep the message components. $error = $e->getMessage(); $file = $e->getFile(); $line = $e->getLine(); $error = sprintf($errorString, $severity, $error, $file, $line); return $error; }
public function test() { $exception = new ErrorException(E_NOTICE, 'message', 'file', 0, 1); $this->assertSame(E_NOTICE, $exception->getSeverity()); $this->assertSame('message', $exception->getMessage()); $this->assertSame('Notice', $exception->getSeverityAsString()); $this->assertSame('E_NOTICE', $exception->getSeverityAsConstantName()); $this->assertSame('file', $exception->getFile()); $this->assertSame(0, $exception->getLine()); $sourceTrace = array_slice($exception->getTrace(), 1); $this->assertSame($sourceTrace, $exception->getSourceTrace()); $this->assertSame(StackTraceFormatter::format($exception->getSourceTrace()), $exception->getSourceTraceAsString()); $this->assertSame('exception \'Hyperframework\\Common\\ErrorException\' ' . "with message 'message' in file:0" . PHP_EOL . 'Stack trace:' . PHP_EOL . $exception->getSourceTraceAsString(), (string) $exception); }
/** * Helper for getting an output style for the given ErrorException's level. * * @param \ErrorException $e * * @return string */ protected function getSeverity(\ErrorException $e) { $severity = $e->getSeverity(); if ($severity & error_reporting()) { switch ($severity) { case E_WARNING: case E_NOTICE: case E_CORE_WARNING: case E_COMPILE_WARNING: case E_USER_WARNING: case E_USER_NOTICE: case E_STRICT: return 'warning'; default: return 'error'; } } else { // Since this is below the user's reporting threshold, it's always going to be a warning. return 'warning'; } }
* it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * MPF Framework is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with MPF Framework. If not, see <http://www.gnu.org/licenses/>. */ define('LIBS_FOLDER', dirname(__DIR__) . DIRECTORY_SEPARATOR); define('APP_ROOT', __DIR__ . DIRECTORY_SEPARATOR); /** * Set ErrorException for every error; */ set_error_handler(function ($errno, $errstr, $errfile, $errline) { $severity = 1 * E_ERROR | 1 * E_WARNING | 1 * E_PARSE | 1 * E_NOTICE | 0 * E_CORE_ERROR | 0 * E_CORE_WARNING | 0 * E_COMPILE_ERROR | 0 * E_COMPILE_WARNING | 1 * E_USER_ERROR | 1 * E_USER_WARNING | 1 * E_USER_NOTICE | 0 * E_STRICT | 0 * E_RECOVERABLE_ERROR | 0 * E_DEPRECATED | 0 * E_USER_DEPRECATED; $ex = new ErrorException($errstr, 0, $errno, $errfile, $errline); if (($ex->getSeverity() & $severity) != 0) { throw $ex; } }); require_once LIBS_FOLDER . 'mpf' . DIRECTORY_SEPARATOR . 'base' . DIRECTORY_SEPARATOR . 'AutoLoader.php'; mpf\base\AutoLoader::get()->register(); use mpf\WebApp as App; use mpf\base\Config; new Config(__DIR__ . DIRECTORY_SEPARATOR . 'config/web.inc.php'); \mpf\base\AutoLoader::get()->applyConfig(Config::get()->forClass('\\mpf\\base\\AutoLoader')); App::run(array('requestClass' => '\\mpf\\web\\request\\SOAP'));
public function __construct($message, \ErrorException $previous) { parent::__construct($message, $previous->getCode(), $previous->getSeverity(), $previous->getFile(), $previous->getLine(), $previous->getPrevious()); $this->setTrace($previous->getTrace()); }
/** * Log an exception that wasn't thrown but made to wrap an error. * * @since 1.25 * @param ErrorException $e * @param string $channel */ protected static function logError(ErrorException $e, $channel) { global $wgLogExceptionBacktrace; // The set_error_handler callback is independent from error_reporting. // Filter out unwanted errors manually (e.g. when MediaWiki\suppressWarnings is active). $suppressed = (error_reporting() & $e->getSeverity()) === 0; if (!$suppressed) { $log = self::getLogMessage($e); if ($wgLogExceptionBacktrace) { wfDebugLog($channel, $log . "\n" . $e->getTraceAsString()); } else { wfDebugLog($channel, $log); } } // Include all errors in the json log (surpressed errors will be flagged) $json = self::jsonSerializeException($e, false, FormatJson::ALL_OK); if ($json !== false) { wfDebugLog("{$channel}-json", $json, 'private'); } Hooks::run('LogException', array($e, $suppressed)); }
/** * Log an exception that wasn't thrown but made to wrap an error. * * @since 1.25 * @param ErrorException $e * @param string $channel */ protected static function logError(ErrorException $e, $channel) { // The set_error_handler callback is independent from error_reporting. // Filter out unwanted errors manually (e.g. when // MediaWiki\suppressWarnings is active). $suppressed = (error_reporting() & $e->getSeverity()) === 0; if (!$suppressed) { $logger = LoggerFactory::getInstance($channel); $logger->error(self::getLogMessage($e), self::getLogContext($e)); } // Include all errors in the json log (surpressed errors will be flagged) $json = self::jsonSerializeException($e, false, FormatJson::ALL_OK); if ($json !== false) { $logger = LoggerFactory::getInstance("{$channel}-json"); $logger->error($json, ['private' => true]); } Hooks::run('LogException', [$e, $suppressed]); }
/** * Log error exceptions to user console using JSON_Response::error * * @param ErrorException $err_exc The error exception * @return void * @uses JSON_Response */ public function consoleErrorException(\ErrorException $err_exc) { Core\JSON_Response::load()->error(['message' => $err_exc->getMessage(), 'code' => $err_exc->getCode(), 'severity' => $err_exc->getSeverity(), 'line' => $err_exc->getLine(), 'file' => $err_exc->getFile(), 'trace' => $err_exc->getTrace()]); }
/** * @param \ErrorException $e * @return array */ public static function createFromPHPError(\ErrorException $e) { return ['message' => $e->getMessage(), 'severity' => $e->getSeverity(), 'trace' => self::toSafeTrace($e->getTrace())]; }