Skip to content

Instantly share code, notes, and snippets.

@ryantxr
Created November 26, 2018 18:36
Show Gist options
  • Save ryantxr/89d8f65b1d2d31b8c2e95a608ef3fdaf to your computer and use it in GitHub Desktop.
Save ryantxr/89d8f65b1d2d31b8c2e95a608ef3fdaf to your computer and use it in GitHub Desktop.
Capture ALL SQL to a separate sql.log
// Capture ALL SQL to a separate sql.log
// In config/logging.php add the following to the channel list
'sql' => [
'driver' => 'single',
'path' => storage_path('logs/sql.log'),
'level' => 'debug',
],
// In app/Providers/AppServiceProvider.php add the following to the boot() method.
\DB::listen(
function($sql) {
\Illuminate\Support\Facades\Log::channel('sql')->debug('sql = '.var_export($sql->sql, true));
\Illuminate\Support\Facades\Log::channel('sql')->debug('bindings = '.var_export($sql->bindings, true));
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment