Yii2 log output to file and database

Source: Internet
Author: User
Tags yii

Edit config/web.php

First log to open

    ' Bootstrap ' = [        ' log '    ],

  

[File]

    ' Components ' and [        ' log ' = ' = '            targets ' and ' = ' [                    ' class ' = ' Yii\log\filetarget ',                    ' Exportinterval ' = 1,],],        ,

  

Default output to Runtime/logs/app.log

Note the webserver or console user must have permission to write to the file

[Database]

        ' Log ' = = ['            targets ' = ['                class ' = '                    yii\log\dbtarget ',                    ' levels ' and ' = ' error ', ' warning ', ' Trace '], []]        ,

The default output DB component corresponds to the database under the {{%log}} table

Run the following command in the root directory of YII2 to generate the corresponding table schema

./yii Migrate--migrationpath=[email protected]/log/migrations/

Note that the same configuration as the web.php is config/console.php, otherwise the command execution is unsuccessful.

You can also configure different logging modes depending on the environment

    ' Components ' = [        ' log ' = ' = '            traceLevel ' = ' = ' dev '? 3:0,            ' targets ' and ' = ['                    C Lass ' = ' yii\log\dbtarget ',                    ' levels ' and yii_debug? [' Error ', ' Warning ', ' Trace ']: [' Error '],                [                    ' class ' = ' Yii\log\filetarget ',                    ' levels ' = Yii_debug? [' Error ', ' Warning ', ' Trace ']: [' Error ', ' warning '],],],],    

  

Yii2 log output to file and database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.