Commit e2de2181 authored by luhongguang's avatar luhongguang

update:统一调整

parent 34b0f978
...@@ -7,6 +7,7 @@ namespace App\Exception; ...@@ -7,6 +7,7 @@ namespace App\Exception;
* 重写Handle的render方法,实现自定义异常消息 * 重写Handle的render方法,实现自定义异常消息
*/ */
use Api\PhpUtils\Log\FileLog;
use Helpers\ApiResponse; use Helpers\ApiResponse;
use Yaf\Registry; use Yaf\Registry;
...@@ -20,10 +21,8 @@ class ErrorHandler ...@@ -20,10 +21,8 @@ class ErrorHandler
public function render($errno, $errstr, $errfile, $errline) public function render($errno, $errstr, $errfile, $errline)
{ {
$debug = Registry::get('config')->debug;
$msg = ' file_name : '.$errfile . '<br> line_num : '.$errline . '<br> message : ' . $errstr; $msg = ' file_name : '.$errfile . '<br> line_num : '.$errline . '<br> message : ' . $errstr;
if($debug){ if(_IS_DEBUG){
echo $msg; echo $msg;
exit; exit;
} }
...@@ -40,6 +39,6 @@ class ErrorHandler ...@@ -40,6 +39,6 @@ class ErrorHandler
*/ */
private function recordErrorLog($msg) private function recordErrorLog($msg)
{ {
// LogUtil::error('Error handler', $msg); FileLog::error('Error handler', $msg);
} }
} }
\ No newline at end of file
...@@ -8,6 +8,7 @@ namespace App\Exception; ...@@ -8,6 +8,7 @@ namespace App\Exception;
* 重写Handle的render方法,实现自定义异常消息 * 重写Handle的render方法,实现自定义异常消息
*/ */
use Api\PhpUtils\Log\FileLog;
use Helpers\ApiResponse; use Helpers\ApiResponse;
use Yaf\Registry; use Yaf\Registry;
...@@ -20,25 +21,21 @@ class ExceptionHandler ...@@ -20,25 +21,21 @@ class ExceptionHandler
public function render(\Throwable $e) public function render(\Throwable $e)
{ {
$debug = Registry::get('config')->debug; if ($e instanceof BaseException) {
if ($e instanceof BaseException)
{
// 自定义异常 // 自定义异常
$this->code = $e->code; $this->code = $e->code;
$this->msg = $e->msg; $this->msg = $e->msg;
} } else {
else{
// 服务器未处理异常 // 服务器未处理异常
if($debug){ if (_IS_DEBUG) {
$message = $e->getMessage(); $message = $e->getMessage();
$file_name = $e->getFile(); $file_name = $e->getFile();
$line_num = $e->getLine(); $line_num = $e->getLine();
echo ' file_name : '.$file_name . '<br> line_num : '.$line_num . '<br> message : ' . $message; echo ' file_name : ' . $file_name . '<br> line_num : ' . $line_num . '<br> message : ' . $message;
exit; exit;
} }
$this->msg = Registry::get('config')->exception->sys->msg; $this->msg = Registry::get('config')->exception->sys->msg;
$this->code = Registry::get('config')->exception->sys->code; $this->code = Registry::get('config')->exception->sys->code;
$this->recordErrorLog($e); $this->recordErrorLog($e);
} }
...@@ -50,16 +47,16 @@ class ExceptionHandler ...@@ -50,16 +47,16 @@ class ExceptionHandler
*/ */
private function recordErrorLog($e) private function recordErrorLog($e)
{ {
if($e instanceof \ErrorException || $e instanceof \Exception){ if ($e instanceof \ErrorException || $e instanceof \Exception || $e instanceof \Error) {
$message = $e->getMessage(); $message = $e->getMessage();
$file_name = $e->getFile(); $file_name = $e->getFile();
$line_num = $e->getLine(); $line_num = $e->getLine();
$msg = ' file_name : '.$file_name . ' line_num : '.$line_num . ' message : ' . $message; $msg = ' file_name : ' . $file_name . ' line_num : ' . $line_num . ' message : ' . $message;
// LogUtil::error('exception handler', $msg); FileLog::error(get_class($e) . ' handler', $msg, $e, 'luhongguang@yidian-inc.com');
} }
if(is_string($e) || is_int($e)){ if (is_string($e) || is_int($e)) {
// LogUtil::error('exception handler', $e); FileLog::error('exception handler', $e);
} }
} }
} }
\ No newline at end of file
...@@ -16,7 +16,7 @@ class Hook extends \Yaf\Plugin_Abstract { ...@@ -16,7 +16,7 @@ class Hook extends \Yaf\Plugin_Abstract {
public function routerShutdown(\Yaf\Request_Abstract $request, \Yaf\Response_Abstract $response) { public function routerShutdown(\Yaf\Request_Abstract $request, \Yaf\Response_Abstract $response) {
/*---Debug Begin---*/ /*---Debug Begin---*/
if((defined('_IS_DEBUG') && _IS_DEBUG) || (isset($_REQUEST['__debug']) && strpos($_REQUEST['__debug'], _DEBUG_PASS) !== false)) if((defined('_IS_DEBUG') && _IS_DEBUG) && (isset($_REQUEST['__debug']) && strpos($_REQUEST['__debug'], _DEBUG_PASS) !== false))
{ {
// $_REQUEST['__debug'] = _DEBUG_PASS + 1 (2 数字表示级别 ) // $_REQUEST['__debug'] = _DEBUG_PASS + 1 (2 数字表示级别 )
$debug_level = intval(substr($_REQUEST['__debug'], -1)); $debug_level = intval(substr($_REQUEST['__debug'], -1));
......
<?php <?php
ini_set("display_errors", "On"); /* 根据 yaf.environ 配置设置报错处理方式 */
$environ = ini_get('yaf.environ');
if(in_array($environ, ['dev'])) {
ini_set("display_errors", "On");
error_reporting(E_ALL);
// 异常信息等级
define('_ERROR_LEVEL', E_ALL);
define('_IS_DEBUG', true);
} else {
ini_set("display_errors", "Off");
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);
// 异常信息等级
define('_ERROR_LEVEL', E_ALL & ~E_DEPRECATED & ~E_STRICT);
define('_IS_DEBUG', false);
}
/* 定义这个常量是为了在application.ini中引用*/ /* 定义这个常量是为了在application.ini中引用*/
define('ROOT_PATH', realpath(__DIR__.'/../')); define('ROOT_PATH', realpath(__DIR__.'/../'));
...@@ -10,9 +27,6 @@ define('APP_START', microtime(true)); ...@@ -10,9 +27,6 @@ define('APP_START', microtime(true));
// 调试参数 __debug 的值 // 调试参数 __debug 的值
define('_DEBUG_PASS', 'debugpass'); // 为了避免调试信息泄漏,请定义自己的密钥 define('_DEBUG_PASS', 'debugpass'); // 为了避免调试信息泄漏,请定义自己的密钥
// 是否开启调试状态 // 是否开启调试状态
define('_IS_DEBUG', false);
// 异常信息等级
define('_ERROR_LEVEL', E_ALL);
$application = new Yaf\Application( ROOT_PATH . "/conf/application.ini"); $application = new Yaf\Application( ROOT_PATH . "/conf/application.ini");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment