3 Commits

Author SHA1 Message Date
wolfcode
dfe15f7e88 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>
2024-10-12 17:21:56 +08:00
wolfcode
4d7365921e chore(deps): bump wolf-leo/phplogviewer from 0.08.0 to 0.10.0
Update the wolf-leo/phplogviewer package from version 0.08.0 to 0.10.0 in composer.json.
This update may include new features, bug fixes, and performance improvements in the PHP log viewer library.

- Update wolf-leo/phplogviewer from ^0.08.0 to ^0.10.0 in composer.json
- Modify return type of System\Log\record() method to Json|string for improved type hinting

Signed-off-by: wolfcode <37436228+wolf-leo@users.noreply.github.com>
2024-10-12 14:00:14 +08:00
wolfcode
d613f3c26f Update composer.json 2024-10-10 15:01:51 +08:00
3 changed files with 20 additions and 4 deletions

View File

@@ -22,6 +22,7 @@ use think\response\Json;
*/
class Log extends AdminController
{
protected array $ignoreLog = ['record'];
public function __construct(App $app)
{
@@ -98,7 +99,7 @@ class Log extends AdminController
/**
* @NodeAnnotation(title="框架日志")
*/
public function record(): string
public function record(): Json|string
{
return (new \Wolfcode\PhpLogviewer\thinkphp\LogViewer())->fetch();
}

View File

@@ -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();

View File

@@ -37,7 +37,7 @@
"qiniu/php-sdk": "v7.11.0",
"ext-mysqli": "*",
"ext-pdo": "*",
"wolf-leo/phplogviewer": "^0.05.0"
"wolf-leo/phplogviewer": "^0.10.0"
},
"require-dev": {
"symfony/var-dumper": ">=4.2",