Yii framework logging Logging operation example

2929 단어
The example of this article describes the Yii framework logging Logging operation. Share for your reference, the details are as follows:

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');
In config, main.php configuration


components->log


default allocation:


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


Revise


'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,
        ],
      ],
    ],


Output log:


Yii::getLogger()->log(" ",Logger::LEVEL_ERROR);
Yii::trace("trace, ");
Yii::error("error, ");
Yii::warning("warning, ");
Yii::info("info, ");




Yii::info("info .... ","rhythmk");
// ,@app/runtime/logs/Mylog/requests.log


Readers who are interested in more about Yii-related content can check the topics on this site: "Introduction to Yii Framework and Summary of Common Skills", "Summary of Excellent PHP Development Framework", "Basic Tutorial for Getting Started with Smarty Templates", "Introduction to PHP Object-Oriented Programming Tutorial"", "php string (string) usage summary", "php+mysql database operation tutorial"and "php common database operation skills summary"
I hope this article will be helpful to everyone in PHP programming based on Yii framework.

좋은 웹페이지 즐겨찾기