@@ -69,7 +69,30 @@ protected function mergeConfigFrom($path, $key)
6969    public  function  boot ()
7070    {
7171
72-         if  (($ this  ->app ['config ' ]->get ('monitor.app ' ) == "local " ) || $ this  ->app ['config ' ]->get ('monitor.sql-monitor ' )) {
72+         if  (($ this  ->app ['config ' ]->get ('monitor.app ' ) == "local " ) || //开启配置APP_ENV配置为local启动 
73+             $ this  ->app ['config ' ]->get ('monitor.debug ' ) || //开启debug模式,默认自动启东监听 
74+             $ this  ->app ['config ' ]->get ('monitor.sql-monitor ' )) //开启配置SQL_MONITOR配置为true启动(为不影响APP_ENV和APP_DEBUG配置,单独设置sql监控的开启配置) 
75+         {
76+ 
77+             //获取当前访问的路径地址和要匹配的路由,进行匹配指定的监控路径 
78+             $ urlPath  = Request::capture ()->path ();
79+             $ monitorActions  = $ this  ->app ['config ' ]->get ('monitor.monitor-action ' );
80+             $ monitorActions  = array_unique (array_filter (explode ("| " , $ monitorActions )));
81+             if  (empty ($ urlPath ) || empty ($ monitorActions )) {
82+                 return  true ;
83+             }
84+ 
85+             //匹配当前的路径是否在配置的路径中 
86+             $ matching  = false ;
87+             foreach  ($ monitorActions  as  $ monitorAction ) {
88+                 if  (strstr (trim ($ urlPath ), trim ($ monitorAction ))) {
89+                     $ matching  = true ;
90+                     break ;
91+                 }
92+             }
93+             if  (!$ matching ) {
94+                 true ;
95+             }
7396
7497            $ db  = $ this  ->app ['db ' ];
7598            $ db ->listen (
@@ -89,8 +112,6 @@ function ($query) {
89112        }
90113    }
91114
92- 
93- 
94115    /** 
95116     * 监听 
96117     * @auther zhanghy<[email protected] > @@ -99,8 +120,8 @@ function ($query) {
99120     */ 
100121    private  function  sqlMonitor (QueryExecuted   $ event , array  $ stacks )
101122    {
102-         $ sql  = str_replace ("? " , "'%s' " , $ event ->sql );
103-         $ sql  = vsprintf ($ sql , $ event ->bindings );
123+ //         $sql = str_replace("?", "'%s'", $event->sql);
124+ //         $sql = vsprintf($sql, $event->bindings);
104125        $ urlPath  = Request::capture ()->path ();
105126
106127        //检索执行的文件和行数 
@@ -115,9 +136,9 @@ private function sqlMonitor(QueryExecuted $event, array $stacks)
115136
116137        //记录日志 
117138        Log::info (json_encode ([
118-             'action '  => 'sqlmonitor : ' . $ urlPath ,
119-             'path '  => $ urlPath  ,
120-             'sql '  => $ sql  ,
139+             'action '  => 'sql_monitor_action : ' . $ urlPath ,
140+             'sql '  => $ event -> sql ,
141+             'bindings '  => $ event -> bindings ,
121142            'time '  => $ event ->time  . 'ms ' ,
122143            'file '  => ($ res ['file ' ] ?? '' ),
123144            'line '  => ($ res ['line ' ] ?? '' )
0 commit comments