YII2 a custom log path

Source: Internet
Author: User

The log write method provided by YII:

1, Yii::getlogger ()->log ($message, $level, $category = ' application ')

2, Yii::trace ($message, $category = ' application ');

3, Yii::error ($message, $category = ' application ');
4, Yii::warning ($message, $category = ' application ');
5, Yii::info ($message, $category = ' application ');


Configuration:
/config/web.php
  Components->log
Default configuration:
'Log'= [            'TraceLevel'= Yii_debug?3:0,            'Targets'= [                [                    'class'='Yii\log\filetarget',                    'levels'= ['Error','Warning'],                ],            ],        ],

The configuration is now modified as follows:

'Log'= [            'TraceLevel'= Yii_debug?3:0,            'Targets'= [                [                    'class'='Yii\log\filetarget',                    'levels'= ['Error','Warning','Info','Trace'],                ],                [                    'class'='Yii\log\filetarget',                    'levels'= ['Info'],                    'Categories'= ['RHYTHMK'],                    'LogFile'='@app/runtime/logs/mylog/requests.log',                    'MaxFileSize'=1024x768*2,                    'Maxlogfiles'= -,                ],            ],        ],

Output log:

Yii::getlogger ()->log ("Start writing custom Log", Logger::level_error);

Yii::trace ("Trace, logging when developing and debugging");

Yii::error ("error log");

Yii::warning ("Warning, warning message");

Yii::info ("info, record operation Tips");

Output Custom Directory Logs

       The log file is in the output directory  @app/runtime/logs/mylog/requests.log        yii::info ("info .... "," RHYTHMK ");

YII2 a custom log path

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.