Issue
I followed the instructions to enable query logging in cakephp v3.
http://book.cakephp.org/3.0/en/orm/database-basics.html#query-logging
// Turn query logging on.
$conn->logQueries(true);
// Turn query logging off
$conn->logQueries(false);
use Cake\Log\Log;
// Console logging
Log::config('queries', [
'className' => 'Console',
'stream' => 'php://stderr',
'scopes' => ['queriesLog']
]);
// File logging
Log::config('queries', [
'className' => 'File',
'path' => LOGS,
'file' => 'queries.log',
'scopes' => ['queriesLog']
]);
After enabling query logging, I am not able to find the log file. I looked under the logs folder. I don't see any queries.log
. Where can the log file be found?
Solution
I've created a test project. Created a simple model so I can parse the data.
In the controller, I added these namespaces:
use App\Model\Table\User; // <---My model
use Cake\ORM\TableRegistry;
use Cake\Log\Log;
use Cake\Datasource\ConnectionManager;
Here's the basic data parse in a controller:
$conn = ConnectionManager::get('default');
Log::config('queries', [
'className' => 'File',
'path' => LOGS,
'file' => 'queries.log',
'scopes' => ['queriesLog']
]);
$users = TableRegistry::get('User');
$conn->logQueries(true);
$q = $users->find('all');
$results = $q->all();
$conn->logQueries(false);
All of this works just great.
Answered By - Andrius Answer Checked By - Timothy Miller (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.