Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
goods
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bp
goods
Commits
e2de2181
Commit
e2de2181
authored
Jul 14, 2021
by
luhongguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update:统一调整
parent
34b0f978
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
23 deletions
+33
-23
ErrorHandler.php
application/exception/ErrorHandler.php
+3
-4
ExceptionHandler.php
application/exception/ExceptionHandler.php
+11
-14
Hook.php
application/plugins/Hook.php
+1
-1
index.php
public/index.php
+18
-4
No files found.
application/exception/ErrorHandler.php
View file @
e2de2181
...
...
@@ -7,6 +7,7 @@ namespace App\Exception;
* 重写Handle的render方法,实现自定义异常消息
*/
use
Api\PhpUtils\Log\FileLog
;
use
Helpers\ApiResponse
;
use
Yaf\Registry
;
...
...
@@ -20,10 +21,8 @@ class ErrorHandler
public
function
render
(
$errno
,
$errstr
,
$errfile
,
$errline
)
{
$debug
=
Registry
::
get
(
'config'
)
->
debug
;
$msg
=
' file_name : '
.
$errfile
.
'<br> line_num : '
.
$errline
.
'<br> message : '
.
$errstr
;
if
(
$debug
){
if
(
_IS_DEBUG
){
echo
$msg
;
exit
;
}
...
...
@@ -40,6 +39,6 @@ class ErrorHandler
*/
private
function
recordErrorLog
(
$msg
)
{
// LogUtil
::error('Error handler', $msg);
FileLog
::
error
(
'Error handler'
,
$msg
);
}
}
\ No newline at end of file
application/exception/ExceptionHandler.php
View file @
e2de2181
...
...
@@ -8,6 +8,7 @@ namespace App\Exception;
* 重写Handle的render方法,实现自定义异常消息
*/
use
Api\PhpUtils\Log\FileLog
;
use
Helpers\ApiResponse
;
use
Yaf\Registry
;
...
...
@@ -20,25 +21,21 @@ class ExceptionHandler
public
function
render
(
\Throwable
$e
)
{
$debug
=
Registry
::
get
(
'config'
)
->
debug
;
if
(
$e
instanceof
BaseException
)
{
if
(
$e
instanceof
BaseException
)
{
// 自定义异常
$this
->
code
=
$e
->
code
;
$this
->
msg
=
$e
->
msg
;
}
else
{
}
else
{
// 服务器未处理异常
if
(
$debug
)
{
if
(
_IS_DEBUG
)
{
$message
=
$e
->
getMessage
();
$file_name
=
$e
->
getFile
();
$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
;
}
$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
->
recordErrorLog
(
$e
);
}
...
...
@@ -50,16 +47,16 @@ class ExceptionHandler
*/
private
function
recordErrorLog
(
$e
)
{
if
(
$e
instanceof
\ErrorException
||
$e
instanceof
\Exception
)
{
if
(
$e
instanceof
\ErrorException
||
$e
instanceof
\Exception
||
$e
instanceof
\Error
)
{
$message
=
$e
->
getMessage
();
$file_name
=
$e
->
getFile
();
$line_num
=
$e
->
getLine
();
$msg
=
' file_name : '
.
$file_name
.
' line_num : '
.
$line_num
.
' message : '
.
$message
;
// LogUtil::error('exception handler', $msg
);
$msg
=
' file_name : '
.
$file_name
.
' line_num : '
.
$line_num
.
' message : '
.
$message
;
FileLog
::
error
(
get_class
(
$e
)
.
' handler'
,
$msg
,
$e
,
'luhongguang@yidian-inc.com'
);
}
if
(
is_string
(
$e
)
||
is_int
(
$e
))
{
// LogUtil
::error('exception handler', $e);
if
(
is_string
(
$e
)
||
is_int
(
$e
))
{
FileLog
::
error
(
'exception handler'
,
$e
);
}
}
}
\ No newline at end of file
application/plugins/Hook.php
View file @
e2de2181
...
...
@@ -16,7 +16,7 @@ class Hook extends \Yaf\Plugin_Abstract {
public
function
routerShutdown
(
\Yaf\Request_Abstract
$request
,
\Yaf\Response_Abstract
$response
)
{
/*---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 数字表示级别 )
$debug_level
=
intval
(
substr
(
$_REQUEST
[
'__debug'
],
-
1
));
...
...
public/index.php
View file @
e2de2181
<?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中引用*/
define
(
'ROOT_PATH'
,
realpath
(
__DIR__
.
'/../'
));
...
...
@@ -10,9 +27,6 @@ define('APP_START', microtime(true));
// 调试参数 __debug 的值
define
(
'_DEBUG_PASS'
,
'debugpass'
);
// 为了避免调试信息泄漏,请定义自己的密钥
// 是否开启调试状态
define
(
'_IS_DEBUG'
,
false
);
// 异常信息等级
define
(
'_ERROR_LEVEL'
,
E_ALL
);
$application
=
new
Yaf\Application
(
ROOT_PATH
.
"/conf/application.ini"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment