mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 07:12:47 +08:00
添加日志记录,以及添加异常忽略支持
异常忽略支持忽略指定的异常类型,被忽略的异常仅仅记录到日志,不会中断程序执行 忽略的异常类型支持PHP的所有错误级别,多个级别支持 | 运算符 参考:http://php.net/manual/en/errorfunc.constants.php
This commit is contained in:
@@ -105,6 +105,9 @@ return [
|
|||||||
|
|
||||||
// 异常页面的模板文件
|
// 异常页面的模板文件
|
||||||
'exception_tmpl' => THINK_PATH . 'tpl' . DS . 'think_exception.tpl',
|
'exception_tmpl' => THINK_PATH . 'tpl' . DS . 'think_exception.tpl',
|
||||||
|
// 异常处理忽略的错误类型,支持PHP所有的错误级别常量,多个级别可以用|运算法
|
||||||
|
// 参考:http://php.net/manual/en/errorfunc.constants.php
|
||||||
|
'exception_ignore_type' => 0,
|
||||||
// 错误显示信息,非调试模式有效
|
// 错误显示信息,非调试模式有效
|
||||||
'error_message' => '页面错误!请稍后再试~',
|
'error_message' => '页面错误!请稍后再试~',
|
||||||
// 错误定向页面
|
// 错误定向页面
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
namespace think;
|
namespace think;
|
||||||
|
|
||||||
use think\Exception;
|
|
||||||
use think\exception\ErrorException;
|
use think\exception\ErrorException;
|
||||||
|
|
||||||
class Error
|
class Error
|
||||||
@@ -73,6 +72,9 @@ class Error
|
|||||||
'message' => Config::get('show_error_msg') ? $exception->getMessage() : Config::get('error_message'),
|
'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);
|
self::output($exception, $data);
|
||||||
// 禁止往下传播已处理过的异常
|
// 禁止往下传播已处理过的异常
|
||||||
@@ -89,10 +91,15 @@ class Error
|
|||||||
*/
|
*/
|
||||||
public static function appError($errno, $errstr, $errfile, $errline)
|
public static function appError($errno, $errstr, $errfile, $errline)
|
||||||
{
|
{
|
||||||
// 将错误信息托管至 think\exception\ErrorException
|
if ($errno & Config::get('exception_ignore_type')) {
|
||||||
throw new ErrorException($errno, $errstr, $errfile, $errline);
|
// 忽略的异常记录到日志
|
||||||
// 禁止往下传播已处理过的异常
|
Log::record("[{$data['code']}]{$data['message']}[{$data['file']}:{$data['line']}]", 'notic');
|
||||||
return true;
|
} else {
|
||||||
|
// 将错误信息托管至 think\exception\ErrorException
|
||||||
|
throw new ErrorException($errno, $errstr, $errfile, $errline);
|
||||||
|
// 禁止往下传播已处理过的异常
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -101,6 +108,9 @@ class Error
|
|||||||
*/
|
*/
|
||||||
public static function appShutdown()
|
public static function appShutdown()
|
||||||
{
|
{
|
||||||
|
// 写入日志
|
||||||
|
Log::save();
|
||||||
|
|
||||||
if ($error = error_get_last()) {
|
if ($error = error_get_last()) {
|
||||||
// 将错误信息托管至think\ErrorException
|
// 将错误信息托管至think\ErrorException
|
||||||
$exception = new ErrorException(
|
$exception = new ErrorException(
|
||||||
|
|||||||
Reference in New Issue
Block a user