Home > PHP Framework > YII > body text

yii2 uses database to record error information

王林
Release: 2020-02-26 16:25:16
Original
2555 people have browsed it

yii2 uses database to record error information

Command line to create error log table

1. Configuration file: console\config\main.php

'components' => [
    'log' => [
        'targets' => [
            [
                'class' => 'yii\log\FileTarget',
                'levels' => ['error', 'warning'],
            ],
            [
                'class' => 'yii\log\DbTarget',  //使用数据库记录日志
                'levels' => ['error', 'warning'],
            ]           
        ],
    ]
],
Copy after login

2. cd to the project root directory , configure the database configuration in the common module, execute the command line to create the table:

(Recommended tutorial: yii framework)

php yii migrate --migrationPath=@yii/log/migrations/
Copy after login

Modify the configuration file: backend\config\main .php

'components' => [
    ... ...
    'log' => [
        'traceLevel' => YII_DEBUG ? 3 : 0,
        'targets' => [
            [
                'class' => 'yii\log\FileTarget',
                'levels' => ['error', 'warning'],
            ],
            [
                'class' => 'yii\log\DbTarget',  //使用数据库记录日志
                'levels' => ['error', 'warning'],
            ]
        ],
    ],
    ... ...
]
Copy after login

For more programming-related content, please pay attention to the Programming Introduction column on the php Chinese website!

The above is the detailed content of yii2 uses database to record error information. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!