YII2 自定義日誌路徑

YII 提供的日誌寫入方法:php

  一、Yii::getLogger()->log($message, $level, $category = 'application')web

  二、Yii::trace($message, $category = 'application');app

三、Yii::error($message, $category = 'application');
四、Yii::warning($message, $category = 'application');
五、Yii::info($message, $category = 'application');


配置:
     /config/web.php
components->log
默認配置:

複製代碼

'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],

複製代碼

現修改配置以下:yii

複製代碼

'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,開發調試時候記錄");component

Yii::error("error,錯誤日誌");開發

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

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

輸出自定義目錄日誌

// 日誌文件在輸出目錄  @app/runtime/logs/Mylog/requests.log
        Yii::info("info .... ","rhythmk");
相關文章
相關標籤/搜索