Where is the log file after enabling query logging

2019-09-02 18:43发布

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?

1条回答
可以哭但决不认输i
2楼-- · 2019-09-02 19:02

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.

查看更多
登录 后发表回答