• YII2 日志


    YII 提供的日志写入方法:

    Yii::getLogger()->log($message, $level, $category = 'application')
    
    Yii::trace($message, $category = 'application');
    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' => 'yiilogFileTarget',
                        'levels' => ['error', 'warning'],
                    ],
                ],
            ],
    复制代码
    
    

    现修改配置如下:

    复制代码
     'log' => [
                'traceLevel' => YII_DEBUG ? 3 : 0,
                'targets' => [
                    [
                        'class' => 'yiilogFileTarget',
                        'levels' => ['error', 'warning','info','trace'],
                    ],
                    [
                        'class' => 'yiilogFileTarget',
                        'levels' => ['info'],
                        'categories' => ['rhythmk'],
                        'logFile' => '@app/runtime/logs/Mylog/requests.log',
                        'maxFileSize' => 1024 * 2,
                        'maxLogFiles' => 20,
                    ],
                ],
            ],
    复制代码

    使用日志(将日志记录到log)

    复制代码
    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");

    整理于:http://www.cnblogs.com/rhythmK/p/4479246.html

  • 相关阅读:
    SpringMVC+Shiro权限管理(转载)
    面试常见问题(转载)
    JavaScript 五种(非构造方式)继承
    JavaScript 五种(构造方式)继承
    Quartz.Net 基于XML配置启动
    jexus防止产生 *.core文件
    Last-Modified、ETag、Expires和Cache-Control
    正则表达式记录
    C# 操作mongodb子文档
    ASP.NET Core "完整发布,自带运行时" 到jexus
  • 原文地址:https://www.cnblogs.com/zjhblogs/p/5786288.html
Copyright © 2020-2023  润新知