本文整理汇总了PHP中Illuminate\Support\Facades\DB::listen方法的典型用法代码示例。如果您正苦于以下问题:PHP DB::listen方法的具体用法?PHP DB::listen怎么用?PHP DB::listen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Facades\DB
的用法示例。
在下文中一共展示了DB::listen方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: boot
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
// If we are in debug mode, listen to database events
// and log queries to the log file.
if (env('DB_DEBUG', false)) {
DB::listen(function ($query) {
$positional = 0;
$full_query = '';
foreach (str_split($query->sql) as $char) {
if ($char === '?') {
$full_query = $full_query . '"' . $query->bindings[$positional] . '"';
$positional++;
} else {
$full_query = $full_query . $char;
}
}
logger()->debug(' ---> QUERY DEBUG: ' . $full_query . ' <---');
});
}
$this->publishes([__DIR__ . '/database/migrations/' => database_path('migrations')]);
}
示例2: boot
/**
* Bootstrap any application services.
*
* 这里面能做很多跟监控有关的事情
*
* @return void
*/
public function boot()
{
// 监听数据库查询 打印LOG
DB::listen(function ($sql, $bindings, $time) {
Log::info('query db' . $sql . ' and the time is ' . $time);
});
}
示例3: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
$monolog = Log::getMonolog();
$monolog->pushHandler(new LDTHandler());
DB::listen(function ($query) {
\DPodsiadlo\LDT\Facades\LDT::query($query);
});
}
示例4: logDb
private function logDb()
{
if (env('APP_DEBUG') === true) {
DB::listen(function ($sql, $bindings, $time) {
$monolog = new Logger('log');
$monolog->pushHandler(new StreamHandler($this->dbLogStoragePath), Logger::INFO);
$monolog->info($sql, compact('bindings', 'time'));
});
}
}
示例5: register
public function register()
{
$log = new Logger('db');
$log->pushHandler(new StreamHandler(storage_path() . '/logs/laravel-db.log'));
DB::listen(function ($sql, $bindings, $time) use($log) {
$sql = str_replace(['%', '?'], ['%%', '%s'], $sql);
$full_sql = vsprintf($sql, $bindings);
//echo PHP_EOL.'- BEGIN QUERY -'.PHP_EOL.$full_sql.PHP_EOL.'- END QUERY -'.PHP_EOL;
$log->addInfo($full_sql);
});
}
示例6: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
view()->composer('home', function ($view) {
//$viewData = $view->getData();
//$charts = Location::findOrFail($viewData['']->charts);
//$view->with('charts', Location::first()->charts);
});
// Logs all SQL queries
DB::listen(function ($sql, $bindings, $time) {
Log::info($sql);
});
}
示例7: bootWhenLocal
protected function bootWhenLocal()
{
//开发环境
if (!$this->app->isLocal()) {
return;
}
//日志
$logger = Log::getMonolog();
$logger->pushHandler(new BrowserConsoleHandler());
//DB事件
DB::listen(function ($query) {
Log::info('sql :' . $query->sql, ['binding' => $query->bindings, 'time' => $query->time]);
});
}