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

致命级错误记录

parent 63750319
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -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));

+3 −3
Original line number Diff line number Diff line
@@ -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 = 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();