Because the built-in database log target can not figure out the context of same request, especially in the case of concurrency, so that the log is very confusing, it is hard to diagnose errors.
According this problem, what this extension do is that record the request ID via dechex($_SERVER['REQUEST_TIME_FLOAT'] * 1000000)
.
composer require razonyang/yii2-log-target-db
return [
// console configuration
'controllerMap' => [
'migrate' => [
'migrationPath' => [
// ...
'@yii/log/migrations/',
],
'migrationNamespaces' => [
// ...
'RazonYang\Yii2\Log\Db\Migration',
],
],
],
// common/web/console configuration
'components' => [
'log' => [
'targets' => [
'db' => [
'class' => \RazonYang\Yii2\Log\Db\Target::class,
'levels' => ['error', 'warning'],
'db' => 'db',
'logTable' => '{{%log}}',
],
],
],
],
];
then:
$ yii migrate