Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
liexin_supplier
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
54e6d6c5
authored
May 31, 2023
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
调试代码
parent
169e1219
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
0 deletions
app/Providers/EventServiceProvider.php
app/Providers/EventServiceProvider.php
View file @
54e6d6c5
...
@@ -3,7 +3,10 @@
...
@@ -3,7 +3,10 @@
namespace
App\Providers
;
namespace
App\Providers
;
use
Illuminate\Contracts\Events\Dispatcher
as
DispatcherContract
;
use
Illuminate\Contracts\Events\Dispatcher
as
DispatcherContract
;
use
Illuminate\Database\Events\QueryExecuted
;
use
Illuminate\Foundation\Support\Providers\EventServiceProvider
as
ServiceProvider
;
use
Illuminate\Foundation\Support\Providers\EventServiceProvider
as
ServiceProvider
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\Log
;
class
EventServiceProvider
extends
ServiceProvider
class
EventServiceProvider
extends
ServiceProvider
{
{
...
@@ -28,6 +31,35 @@ class EventServiceProvider extends ServiceProvider
...
@@ -28,6 +31,35 @@ class EventServiceProvider extends ServiceProvider
{
{
parent
::
boot
(
$events
);
parent
::
boot
(
$events
);
// //监听laravel框架执行的sql语句 并记录到log日志文件中
// DB::listen(function(QueryExecuted $event){
//
// $sql = $event->sql; //执行的sql语句
// $bindings = $event->bindings; //sql语句对应绑定的sql值
// $time = $event->time; //sql执行的时间
//
// $bindings = array_map(function($binding){
// if(is_string($binding))
// {
// return "'$binding'"; //如果$binding是字符串类型 则要将$binding的左右两边拼接上'' 即 字符串=》 '字符串'
// }
// else if($binding instanceof \DateTime)
// {
// return $binding->format("'Y-m-d H:i:s'"); //如果$binding是一个DateTime对象 则格式化时间 并在左右俩边拼接上''
// }
// else
// {
// return $binding; //直接返回$binding原本的值
// }
// }, $bindings);
//
// $sql = str_replace('?', '%s', $sql); //将sql语句中的?换成%s
//// $sql = sprintf($sql, ...$bindings); //将$bindings数组中的每一个元素替换掉$sql中的%s的位置
//
// Log::info("sql_log", ["sql" => $sql, "execute_time" => $time]); //将最终生成的sql语句写入到log日志文件中
//
// });
//
//
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment