Yii Framework Logging Logging Operation Sample

  • 2021-10-25 06:04:43
  • OfStack

This article example describes the Yii framework logging Logging operations. Share it for your reference, 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');

Configuration in config, main. php


components->log

Default configuration:


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

Modify


'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(" Start writing custom logs ",Logger::LEVEL_ERROR);
Yii::trace("trace, Record when developing and debugging ");
Yii::error("error, Error log ");
Yii::warning("warning, Warning message ");
Yii::info("info, Record operation tips ");


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

More readers interested in Yii can check the topics of this site: "Introduction to Yii Framework and Summary of Common Skills", "Summary of Excellent Development Framework of php", "Basic Tutorial for Introduction to smarty Template", "Introduction to php Object-Oriented Programming", "Summary of Usage of php String (string)", "Introduction to php+mysql Database Operation" and "Summary of Common Database Operation Skills of php"

I hope this article is helpful to the PHP programming based on Yii framework.


Related articles: