In plain English: all you have to do is change config / app.php
Find the Datasources configuration and set 'log' => true
'Datasources' => [ 'default' => [ 'className' => 'Cake\Database\Connection', 'driver' => 'Cake\Database\Driver\Mysql', 'persistent' => false, 'host' => 'localhost', ... 'log' => true,
If your application is in debug mode, you will see an SQL query when an SQL error is displayed on your page. If you do not have debug mode, you can register SQL queries in a file by adding the following:
configurations /app.php
Find the Log configuration and add a new log type:
'Log' => [ 'debug' => [ 'className' => 'Cake\Log\Engine\FileLog', 'path' => LOGS, 'file' => 'debug', 'levels' => ['notice', 'info', 'debug'], 'url' => env('LOG_DEBUG_URL', null), ], 'error' => [ 'className' => 'Cake\Log\Engine\FileLog', 'path' => LOGS, 'file' => 'error', 'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'], 'url' => env('LOG_ERROR_URL', null), ],
Your SQL queries will now be written to the log file, which you can find in /logs/queries.log