Ejemplo n.º 1
2
 /**
  * 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')]);
 }
Ejemplo n.º 2
0
 /**
  * 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);
     });
 }
Ejemplo n.º 3
0
 /**
  * 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);
     });
 }
Ejemplo n.º 4
0
 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'));
         });
     }
 }
 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);
     });
 }
Ejemplo n.º 6
0
 /**
  * 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);
     });
 }
 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]);
     });
 }