From 1fc0783ebf3116520f75c1384bd41cc178c4e75f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BA=A6=E5=BD=93=E8=8B=97=E5=84=BF?= Date: Mon, 1 Feb 2016 21:08:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=A5=E5=BF=97=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=EF=BC=8C=E4=BB=A5=E5=8F=8A=E6=B7=BB=E5=8A=A0=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=BF=BD=E7=95=A5=E6=94=AF=E6=8C=81=20=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=BF=BD=E7=95=A5=E6=94=AF=E6=8C=81=E5=BF=BD=E7=95=A5?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E7=9A=84=E5=BC=82=E5=B8=B8=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=EF=BC=8C=E8=A2=AB=E5=BF=BD=E7=95=A5=E7=9A=84=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E4=BB=85=E4=BB=85=E8=AE=B0=E5=BD=95=E5=88=B0=E6=97=A5=E5=BF=97?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E4=BC=9A=E4=B8=AD=E6=96=AD=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=20=E5=BF=BD=E7=95=A5=E7=9A=84=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E7=B1=BB=E5=9E=8B=E6=94=AF=E6=8C=81PHP=E7=9A=84?= =?UTF-8?q?=E6=89=80=E6=9C=89=E9=94=99=E8=AF=AF=E7=BA=A7=E5=88=AB=EF=BC=8C?= =?UTF-8?q?=E5=A4=9A=E4=B8=AA=E7=BA=A7=E5=88=AB=E6=94=AF=E6=8C=81=20|=20?= =?UTF-8?q?=E8=BF=90=E7=AE=97=E7=AC=A6=20=E5=8F=82=E8=80=83=EF=BC=9Ahttp:/?= =?UTF-8?q?/php.net/manual/en/errorfunc.constants.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convention.php | 3 +++ library/think/Error.php | 20 +++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/convention.php b/convention.php index fa1409cb..60bbeeed 100644 --- a/convention.php +++ b/convention.php @@ -105,6 +105,9 @@ return [ // 异常页面的模板文件 'exception_tmpl' => THINK_PATH . 'tpl' . DS . 'think_exception.tpl', + // 异常处理忽略的错误类型,支持PHP所有的错误级别常量,多个级别可以用|运算法 + // 参考:http://php.net/manual/en/errorfunc.constants.php + 'exception_ignore_type' => 0, // 错误显示信息,非调试模式有效 'error_message' => '页面错误!请稍后再试~', // 错误定向页面 diff --git a/library/think/Error.php b/library/think/Error.php index 9370f4d7..331722e4 100644 --- a/library/think/Error.php +++ b/library/think/Error.php @@ -11,7 +11,6 @@ namespace think; -use think\Exception; use think\exception\ErrorException; class Error @@ -73,6 +72,9 @@ class Error 'message' => Config::get('show_error_msg') ? $exception->getMessage() : Config::get('error_message'), ]; } + + // 记录异常日志 + Log::write("[{$data['code']}]{$data['message']}[{$data['file']}:{$data['line']}]", 'error'); // 输出错误信息 self::output($exception, $data); // 禁止往下传播已处理过的异常 @@ -89,10 +91,15 @@ class Error */ public static function appError($errno, $errstr, $errfile, $errline) { - // 将错误信息托管至 think\exception\ErrorException - throw new ErrorException($errno, $errstr, $errfile, $errline); - // 禁止往下传播已处理过的异常 - return true; + if ($errno & Config::get('exception_ignore_type')) { + // 忽略的异常记录到日志 + Log::record("[{$data['code']}]{$data['message']}[{$data['file']}:{$data['line']}]", 'notic'); + } else { + // 将错误信息托管至 think\exception\ErrorException + throw new ErrorException($errno, $errstr, $errfile, $errline); + // 禁止往下传播已处理过的异常 + return true; + } } /** @@ -101,6 +108,9 @@ class Error */ public static function appShutdown() { + // 写入日志 + Log::save(); + if ($error = error_get_last()) { // 将错误信息托管至think\ErrorException $exception = new ErrorException(