feat(admin): 新增过滤不需要记录后台日志的方法 add ignoreLog property to exclude log recording for specific actions
- Add 'ignoreLog' property to the Log controller to specify actions that should not be logged - Implement logic in SystemLog middleware to check if the current action is in the ignoreLog list - Skip logging for actions listed in ignoreLog, improving performance and reducing log clutter Signed-off-by: wolfcode <37436228+wolf-leo@users.noreply.github.com>
This commit is contained in:
@@ -22,6 +22,7 @@ use think\response\Json;
|
||||
*/
|
||||
class Log extends AdminController
|
||||
{
|
||||
protected array $ignoreLog = ['record'];
|
||||
|
||||
public function __construct(App $app)
|
||||
{
|
||||
|
||||
@@ -7,9 +7,11 @@ use app\admin\service\annotation\NodeAnnotation;
|
||||
use app\admin\service\SystemLogService;
|
||||
use app\common\traits\JumpTrait;
|
||||
use app\Request;
|
||||
use ReflectionClass;
|
||||
use Closure;
|
||||
use Doctrine\Common\Annotations\AnnotationReader;
|
||||
use Doctrine\Common\Annotations\DocParser;
|
||||
use ReflectionException;
|
||||
|
||||
class SystemLog
|
||||
{
|
||||
@@ -26,9 +28,13 @@ class SystemLog
|
||||
'mobile',
|
||||
];
|
||||
|
||||
/**
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
$params = $request->param();
|
||||
$response = $next($request);
|
||||
$params = $request->param();
|
||||
if (isset($params['s'])) unset($params['s']);
|
||||
foreach ($params as $key => $val) {
|
||||
in_array($key, $this->sensitiveParams) && $params[$key] = "***********";
|
||||
@@ -39,9 +45,18 @@ class SystemLog
|
||||
if (env('APP_DEBUG')) {
|
||||
trace(['url' => $url, 'method' => $method, 'params' => $params,], 'requestDebugInfo');
|
||||
}
|
||||
$response = $next($request);
|
||||
if ($request->isAjax()) {
|
||||
if (in_array($method, ['post', 'put', 'delete'])) {
|
||||
|
||||
$controller = $request->controller();
|
||||
if (str_contains($controller, '.')) $controller = str_replace('.', '\\', $controller);
|
||||
$action = $request->action();
|
||||
$controllerClass = 'app\\admin\\controller\\' . $controller;
|
||||
$classObj = new ReflectionClass($controllerClass);
|
||||
$properties = $classObj->getDefaultProperties();
|
||||
$ignoreLog = $properties['ignoreLog'] ?? [];
|
||||
if (in_array($action, $ignoreLog)) return $response;
|
||||
|
||||
$title = '';
|
||||
try {
|
||||
$pathInfo = $request->pathinfo();
|
||||
|
||||
Reference in New Issue
Block a user