|
@@ -2,11 +2,12 @@ |
|
@@ -2,11 +2,12 @@ |
|
2
|
|
2
|
|
|
3
|
namespace App\Listeners;
|
3
|
namespace App\Listeners;
|
|
4
|
|
4
|
|
|
5
|
-use Illuminate\Contracts\Queue\ShouldQueue;
|
5
|
+use App\Enums\Common\Common;
|
|
6
|
use Illuminate\Database\Events\QueryExecuted;
|
6
|
use Illuminate\Database\Events\QueryExecuted;
|
|
7
|
-use Illuminate\Queue\InteractsWithQueue;
|
7
|
+use Illuminate\Support\Facades\Cache;
|
|
8
|
use Illuminate\Support\Facades\Log;
|
8
|
use Illuminate\Support\Facades\Log;
|
|
9
|
-use Illuminate\Support\Facades\Redis;
|
9
|
+use Illuminate\Support\Facades\Route;
|
|
|
|
10
|
+use Illuminate\Support\Str;
|
|
10
|
|
11
|
|
|
11
|
/**
|
12
|
/**
|
|
12
|
* 监听数据库sql执行事件
|
13
|
* 监听数据库sql执行事件
|
|
@@ -47,6 +48,33 @@ class QueryListener |
|
@@ -47,6 +48,33 @@ class QueryListener |
|
47
|
$log = $log.' [ RunTime:'.$event->time.'ms ] ';
|
48
|
$log = $log.' [ RunTime:'.$event->time.'ms ] ';
|
|
48
|
Log::debug($log);
|
49
|
Log::debug($log);
|
|
49
|
}
|
50
|
}
|
|
|
|
51
|
+ //监听9644这个api_no是TM咋个被改的
|
|
|
|
52
|
+ if(in_array(9644, $event->bindings) && Str::contains($event->sql, ['update', '`api_no` ='])){
|
|
|
|
53
|
+ //记录debug 根据这个溯源
|
|
|
|
54
|
+ $trace = debug_backtrace();
|
|
|
|
55
|
+ $traces = [];
|
|
|
|
56
|
+ foreach ($trace as $index => $caller) {
|
|
|
|
57
|
+ if ($index === 0) {
|
|
|
|
58
|
+ continue; // 跳过当前方法的调用信息
|
|
|
|
59
|
+ }
|
|
|
|
60
|
+ $file = $caller['file'];
|
|
|
|
61
|
+ $line = $caller['line'];
|
|
|
|
62
|
+ $class = $caller['class'];
|
|
|
|
63
|
+ $method = $caller['function'];
|
|
|
|
64
|
+ $traces[] = "Method $method called from $class in file $file at line $line\n";
|
|
|
|
65
|
+ }
|
|
|
|
66
|
+ //用户信息 哪个改的 还是脚本跑的
|
|
|
|
67
|
+ $token = request()->header('token');
|
|
|
|
68
|
+ Log::channel('test')->info('api_no updated', [
|
|
|
|
69
|
+ 'sql' => $event->sql,
|
|
|
|
70
|
+ 'bindings' => $event->bindings,
|
|
|
|
71
|
+ 'route' => Route::current(),
|
|
|
|
72
|
+ 'request' => request()->all(),
|
|
|
|
73
|
+ 'a_info' => Cache::get(Common::MANAGE_TOKEN . $token),
|
|
|
|
74
|
+ 'b_info' => Cache::get($token),
|
|
|
|
75
|
+ 'trace' => $traces
|
|
|
|
76
|
+ ]);
|
|
|
|
77
|
+ }
|
|
50
|
}catch (\Exception $exception){
|
78
|
}catch (\Exception $exception){
|
|
51
|
Log::error('log sql error:'.$exception->getMessage());
|
79
|
Log::error('log sql error:'.$exception->getMessage());
|
|
52
|
}
|
80
|
}
|