LogTraceAspect.php 1.04 KB
Newer Older
1 2 3 4 5 6
<?php
namespace Meibuyu\Micro\Aspect;

use Hyperf\Di\Annotation\Aspect;
use Hyperf\Di\Aop\AbstractAspect;
use Hyperf\Di\Aop\ProceedingJoinPoint;
Liu lu's avatar
Liu lu committed
7
use Hyperf\HttpServer\Contract\RequestInterface;
8 9 10 11
use Meibuyu\Micro\Annotation\LogTrace;
use Meibuyu\Micro\Handler\LogTrace\LogTraceHandler;

/**
12
 * @Aspect()
13 14 15 16
 */
class LogTraceAspect extends AbstractAspect
{

17 18 19 20
    public $annotations = [
        LogTrace::class
    ];

21 22 23 24 25 26 27 28
    /**
     * 优先级
     * @var int
     */
    public $priority = 999;

    public function process(ProceedingJoinPoint $proceedingJoinPoint)
    {
Liu lu's avatar
Liu lu committed
29 30 31 32 33

        $originParams = [
            'called_params'=>$proceedingJoinPoint->getArguments(),
            'http_params'=>make(RequestInterface::class)->all()
        ];
34 35
        LogTraceHandler::createLogTrace(
            $proceedingJoinPoint->className.'@'.$proceedingJoinPoint->methodName,
Liu lu's avatar
Liu lu committed
36
            $originParams
37 38 39 40 41 42 43
        );
        $result =  $proceedingJoinPoint->process();
        LogTraceHandler::recordProcess('返回结果:'.json_encode($result));

        return $result;
    }
}