YII2 日志


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');


配置:
/config/web.php
  components->log
 默認配置:
'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
 
        

現修改配置如下:

 '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' => 1024 * 2,
                    'maxLogFiles' => 20,
                ],
            ],
        ],

 

輸出日志:

    

       Yii::getLogger()->log("開始寫自定義日志",Logger::LEVEL_ERROR);

        Yii::trace("trace,開發調試時候記錄");

        Yii::error("error,錯誤日志");

        Yii::warning("warning,警告信息");

        Yii::info("info,記錄操作提示");

 

 輸出自定義目錄日志

       // 日志文件在輸出目錄  @app/runtime/logs/Mylog/requests.log
        Yii::info("info .... ","rhythmk");

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM