Exception ‘yii\base\InvalidConfigException’ with message ‘You should configure "log" component to use one or more database targets before executing this migration.’错误

要用数据库存储日志,首先的建表,再是写日志。

配置命令行中components创建log表

return [
    'id' => 'app-console',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'controllerNamespace' => 'console\controllers',
    'controllerMap' => [
        'fixture' => [
            'class' => 'yii\console\controllers\FixtureController',
            'namespace' => 'common\fixtures',
        ],
    ],
    'components' => [
        'log' => [
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
              //添加配置
                [
                    'class' => 'yii\log\DbTarget',  //使用数据库记录日志
                    'levels' => ['error', 'warning'],
                ]
            ],

        ],
    ],
    'params' => $params,
];

运行命令创建表

yii migrate --migrationPath=@yii/log/migrations/

现在可以配置前后台的components中log组件,就不会提示如上错误。

0 条评论
发表一条评论