Commit 147ff147 authored by Liu lu's avatar Liu lu

致命级错误记录

parent 63750319
...@@ -35,6 +35,14 @@ class LogTraceAspect extends AbstractAspect ...@@ -35,6 +35,14 @@ class LogTraceAspect extends AbstractAspect
$proceedingJoinPoint->className.'@'.$proceedingJoinPoint->methodName, $proceedingJoinPoint->className.'@'.$proceedingJoinPoint->methodName,
$originParams $originParams
); );
$requestId = LogTraceHandler::getRequestId();
register_shutdown_function(function ()use($requestId) {
LogTraceHandler::recordProcess(
'致命异常:'.json_encode(error_get_last()),
false,
$requestId
);
});
$result = $proceedingJoinPoint->process(); $result = $proceedingJoinPoint->process();
LogTraceHandler::recordProcess('返回结果:'.json_encode($result)); LogTraceHandler::recordProcess('返回结果:'.json_encode($result));
......
...@@ -66,7 +66,7 @@ class LogTraceHandler ...@@ -66,7 +66,7 @@ class LogTraceHandler
* @return string * @return string
* @throws \Exception * @throws \Exception
*/ */
private static function getRequestId($isInAsyncCoroutine=false) public static function getRequestId($isInAsyncCoroutine=false)
{ {
$workId = posix_getpid(); $workId = posix_getpid();
$cid = Coroutine::id(); $cid = Coroutine::id();
...@@ -92,7 +92,7 @@ class LogTraceHandler ...@@ -92,7 +92,7 @@ class LogTraceHandler
* 待写到Es后可以避免 * 待写到Es后可以避免
* 记录当前日志(包括异常捕获) * 记录当前日志(包括异常捕获)
*/ */
public static function recordProcess($track,$isInAsyncCoroutine=false) public static function recordProcess($track,$isInAsyncCoroutine=false,$requestId=0)
{ {
if (empty($track)) return; if (empty($track)) return;
if(!Coroutine::inCoroutine()) return; if(!Coroutine::inCoroutine()) return;
...@@ -114,7 +114,7 @@ class LogTraceHandler ...@@ -114,7 +114,7 @@ class LogTraceHandler
$logInfo .= "\n\n"; $logInfo .= "\n\n";
container(LogTraceQueue::class)->addToQueue([ container(LogTraceQueue::class)->addToQueue([
'request_id'=>self::getRequestId($isInAsyncCoroutine), 'request_id'=>$requestId?:self::getRequestId($isInAsyncCoroutine),
'process_info'=>$logInfo 'process_info'=>$logInfo
]); ]);
// $log = LogTrace::where('request_id', self::getRequestId())->first(); // $log = LogTrace::where('request_id', self::getRequestId())->first();
......
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