作者 赵彬吉

监听日志

... ... @@ -2,11 +2,12 @@
namespace App\Listeners;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Enums\Common\Common;
use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Str;
/**
* 监听数据库sql执行事件
... ... @@ -47,6 +48,33 @@ class QueryListener
$log = $log.' [ RunTime:'.$event->time.'ms ] ';
Log::debug($log);
}
//监听9644这个api_no是TM咋个被改的
if(in_array(9644, $event->bindings) && Str::contains($event->sql, ['update', '`api_no` ='])){
//记录debug 根据这个溯源
$trace = debug_backtrace();
$traces = [];
foreach ($trace as $index => $caller) {
if ($index === 0) {
continue; // 跳过当前方法的调用信息
}
$file = $caller['file'];
$line = $caller['line'];
$class = $caller['class'];
$method = $caller['function'];
$traces[] = "Method $method called from $class in file $file at line $line\n";
}
//用户信息 哪个改的 还是脚本跑的
$token = request()->header('token');
Log::channel('test')->info('api_no updated', [
'sql' => $event->sql,
'bindings' => $event->bindings,
'route' => Route::current(),
'request' => request()->all(),
'a_info' => Cache::get(Common::MANAGE_TOKEN . $token),
'b_info' => Cache::get($token),
'trace' => $traces
]);
}
}catch (\Exception $exception){
Log::error('log sql error:'.$exception->getMessage());
}
... ...
... ... @@ -72,6 +72,12 @@ return [
'via' => \App\Factory\LogFormatterFactory::class,
'prefix' => 'rank_data',
],
//测试数据日志
'test' => [
'driver' => 'custom',
'via' => \App\Factory\LogFormatterFactory::class,
'prefix' => 'test',
],
'wechatside' => [
'driver' => 'custom',
'via' => \App\Factory\LogFormatterFactory::class,
... ...