Commit 63f4a4e7 authored by Liu lu's avatar Liu lu

致命级错误记录

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