Files
kiri-core/kiri-engine/Error/LoggerAspect.php
T

54 lines
961 B
PHP
Raw Normal View History

2021-03-29 03:09:55 +08:00
<?php
2021-08-11 01:04:57 +08:00
namespace Kiri\Error;
2021-03-29 03:09:55 +08:00
2021-09-06 11:28:59 +08:00
use Exception;
2021-11-19 17:11:17 +08:00
use Http\Aspect\OnAspectInterface;
use Http\Aspect\OnJoinPointInterface;
2021-10-26 11:22:18 +08:00
use Http\Constrict\RequestInterface;
use Kiri\Kiri;
2021-12-03 18:40:27 +08:00
use Psr\Log\LoggerInterface;
2021-03-29 03:09:55 +08:00
/**
* Class LoggerAspect
2021-08-11 01:04:57 +08:00
* @package Kiri\Error
2021-03-29 03:09:55 +08:00
*/
2021-11-19 17:11:17 +08:00
class LoggerAspect implements OnAspectInterface
2021-03-29 03:09:55 +08:00
{
2021-03-29 16:17:22 +08:00
/**
2021-11-19 17:11:17 +08:00
* @param OnJoinPointInterface $joinPoint
2021-03-29 16:17:22 +08:00
* @return mixed
2021-11-19 17:11:17 +08:00
* @throws Exception
2021-03-29 16:17:22 +08:00
*/
2021-11-19 17:11:17 +08:00
public function process(OnJoinPointInterface $joinPoint): mixed
2021-07-27 17:27:56 +08:00
{
2021-11-19 17:11:17 +08:00
$time = microtime(true);
$response = $joinPoint->process();
$this->print_runtime($time);
return $response;
2021-07-27 17:27:56 +08:00
}
2021-03-29 03:09:55 +08:00
2021-04-23 03:12:00 +08:00
2021-07-27 17:27:56 +08:00
/**
* @param $startTime
2021-09-06 11:28:59 +08:00
* @throws Exception
2021-07-27 17:27:56 +08:00
*/
2021-09-06 11:28:59 +08:00
private function print_runtime($startTime)
2021-07-27 17:27:56 +08:00
{
2021-10-26 11:22:18 +08:00
$request = Kiri::getDi()->get(RequestInterface::class);
2021-07-27 17:27:56 +08:00
$runTime = round(microtime(true) - $startTime, 6);
2021-12-03 18:40:27 +08:00
$logger = Kiri::getDi()->get(LoggerInterface::class);
$logger->debug(sprintf('run %s use time %6f', $request->getUri()->__toString(), $runTime));
2021-07-27 17:27:56 +08:00
}
2021-03-29 03:09:55 +08:00
}