日志获取注解标题

This commit is contained in:
wolfcode
2023-11-07 17:23:22 +08:00
parent 67f0c4ce53
commit 7d89af4291
2 changed files with 29 additions and 11 deletions

View File

@@ -2,10 +2,12 @@
namespace app\admin\middleware;
use app\admin\service\annotation\ControllerAnnotation;
use app\admin\service\SystemLogService;
use app\Request;
use app\admin\service\tool\CommonTool;
use think\facade\Log;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\DocParser;
/**
* 系统操作日志中间件
@@ -38,19 +40,34 @@ class SystemLog
$method = strtolower($request->method());
$url = $request->url();
trace([
'url' => $url,
'method' => $method,
'params' => $params,
],
'requestDebugInfo'
);
if (env('APP_DEBUG')) {
trace(['url' => $url, 'method' => $method, 'params' => $params,], 'requestDebugInfo');
}
if ($request->isAjax()) {
if (in_array($method, ['post', 'put', 'delete'])) {
$title = '';
try {
$pathInfo = $request->pathinfo();
$pathInfoExp = explode('/', $pathInfo);
$pathInfoExp = explode('.', $pathInfoExp[0] ?? '');
$_controller = $pathInfoExp[0] ?? '';
$_action = strtolower($pathInfoExp[1] ?? '');
if ($_controller && $_action) {
$className = "app\admin\controller\\{$_controller}\\{$_action}";
$reflectionClass = new \ReflectionClass($className);
$parser = new DocParser();
$parser->setIgnoreNotImportedAnnotations(true);
$reader = new AnnotationReader($parser);
$controllerAnnotation = $reader->getClassAnnotation($reflectionClass, ControllerAnnotation::class);
$title = $controllerAnnotation->title;
}
} catch (\Throwable $exception) {
}
$ip = CommonTool::getRealIp();
$data = [
'admin_id' => session('admin.id'),
'title' => $title,
'url' => $url,
'method' => $method,
'ip' => $ip,