Where is the log file after enabling query logging?

我怕爱的太早我们不能终老 提交于 2019-12-13 05:21:25

问题


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'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.



来源:https://stackoverflow.com/questions/33629642/where-is-the-log-file-after-enabling-query-logging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!