Page Contents

API Query Log

Warning

This feature requires the API listener to work.

This listener appends query log information to the API responses

Note

The listener will only append the queryLog key if debug is set to true.

Setup

Attach it on the fly in your controller beforeFilter, this is recommended if you want to attach it only to specific controllers and actions

<?php
class SamplesController extends AppController {

    public function beforeFilter(\Cake\Event\Event $event) {
        $this->Crud->addListener('Crud.Api'); // Required
        $this->Crud->addListener('Crud.ApiQueryLog');
    }

}

Attach it using components array, this is recommended if you want to attach it to all controllers, application wide

<?php
class AppController extends \Cake\Controller\Controller {

    public function initialize()
    {
        $this->loadComponent('RequestHandler');
        $this->loadComponent('Crud.Crud', [
            'listeners' => [
                'Crud.Api', // Required
                'Crud.ApiQueryLog'
            ]
        ]);
    }
}

Output

Paginated results will include a

{
    "success": true,
    "data": [

    ],
    "queryLog": {
        "default": {
            "log": [
                {
                    "query": "SELECT SOMETHING FROM SOMEWHERE",
                    "took": 2,
                    "params": [

                    ],
                    "affected": 25,
                    "numRows": 25
                },
                {
                    "query": "SELECT SOMETHING FROM SOMEWHERE'",
                    "params": [

                    ],
                    "affected": 1,
                    "numRows": 1,
                    "took": 0
                }
            ]
        }
    }
}
  v: 4.4.3
Versions
latest
stable
4.4.3
4.4.2
4.4.1
4.4.0
4.3.5
4.3.4
4.3.3
4.3.2
4.3.1
4.3.0
4.2.4
4.2.3
4.2.2
4.2.1
4.2.0
4.1.4
v4.0.0
cake3
Downloads
On Read the Docs
Project Home
Builds
Downloads
On GitHub
View
Edit

Free document hosting provided by Read the Docs.