Skip to content

Commit 8a2fed6

Browse files
authored
Merge pull request #9 from zjttfs/main
屏蔽掉指定路径的日志
2 parents 3e212bd + f13e9ba commit 8a2fed6

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/Middleware.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,37 @@ public function process(Request $request, callable $next): Response
3333
{
3434
static $initialized_db, $initialized_think_orm;
3535

36+
$conf=config('plugin.webman.log.app');
37+
38+
//跳过配置的模块
39+
if(!empty($conf['dontReport']['app']) && is_array($conf['dontReport']['app']) && in_array($request->app,$conf['dontReport']['app'],true)){
40+
return $next($request);
41+
}
42+
43+
//跳过配置的path
44+
if(!empty($conf['dontReport']['path']) && is_array($conf['dontReport']['path'])){
45+
$requestPath=$request->path();
46+
foreach ($conf['dontReport']['path'] as $_path){
47+
if(strpos($requestPath,$_path)===0){
48+
return $next($request);
49+
}
50+
}
51+
}
52+
53+
//跳过配置的控制器日志记录
54+
if(!empty($conf['dontReport']['controller']) && is_array($conf['dontReport']['controller']) && in_array($request->controller,$conf['dontReport']['controller'],true)){
55+
return $next($request);
56+
}
57+
58+
//跳过配置的方法
59+
if(!empty($conf['dontReport']['action']) && is_array($conf['dontReport']['action'])){
60+
foreach ($conf['dontReport']['action'] as $_action){
61+
if($_action[0]===$request->controller && $_action[1]===$request->action){
62+
return $next($request);
63+
}
64+
}
65+
}
66+
3667
// 请求开始时间
3768
$start_time = microtime(true);
3869

src/config/plugin/webman/log/app.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,20 @@
88
'dontReport' => [
99
support\exception\BusinessException::class
1010
]
11+
],
12+
'dontReport' => [
13+
'app' => [
14+
'test',
15+
],
16+
'controller' => [
17+
Test::class,
18+
],
19+
'action' => [
20+
[Test::class, 'index'],
21+
],
22+
'path' => [
23+
'/test',
24+
'/test/echo'
25+
]
1126
]
1227
];

0 commit comments

Comments
 (0)