<?php namespace foo\bar; use Yii; use yii\base\Application; use yii\base\BootstrapInterface; use yii\log\Logger; /** * Register the log target when your module is bootstrapped, setting it to only capture DB queries */ class Module extends \yii\base\Module implements BootstrapInterface { /** * @var LogTarget */ public $logTarget; public function bootstrap($app) { /* @var $app Application */ $this->logTarget = $app->getLog()->targets['ray-db'] = Yii::createObject([ 'class' => LogTarget::class, 'module' => $this, 'levels' => Logger::LEVEL_PROFILE, 'categories' => ['yii\db\Command::query', 'yii\db\Command::execute'], ]); } }