美文网首页
YII1日志功能的使用

YII1日志功能的使用

作者: liamu | 来源:发表于2017-04-14 08:51 被阅读107次
  • 1、在项目根目录下的index.php配置如下:
<?php

// change the following paths if necessary
$yii=dirname(__FILE__).'/../../framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';

// remove the following line when in production mode
// defined('YII_DEBUG') or define('YII_DEBUG',true);
defined('YII_DEBUG') or define('YII_DEBUG',true);

defined('YII_DEBUG_SHOW_PROFILER') or define('YII_DEBUG_SHOW_PROFILER',true);
//enable profiling
defined('YII_DEBUG_PROFILING') or define('YII_DEBUG_PROFILING',true);
//trace level
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',9);
//execution time
defined('YII_DEBUG_DISPLAY_TIME') or define('YII_DEBUG_DISPLAY_TIME',true);
require_once($yii);
Yii::createWebApplication($config)->run();

  • 2、在protected/config/main.php配置如下:
        'log'=>array(
            // 信息路由发生在当前请求周期最后的 onEndRequest 事件触发时。 要显式终止当前请求过程,请调用 CApplication::end() 而不是使用 die() 或 exit(),因为 CApplication::end() 将会触发 onEndRequest 事件, 这样信息才会被顺利地记录。
            'class'=>'CLogRouter',
            'routes'=>array(
                array(
                    'class'=>'CFileLogRoute',//它会把信息保存在位于应用程序 runtime 目录中的一个文件中
                    'levels'=>'info, warning',//只有级别为 trace 或 info 
                    'categories' => 'system.*',//分类以 system. 开头的信息才会被保存
                ),
                //开发过程中所有日志直接输出到浏览器了,这样不需要登录服务器看日志了 
                array(
                    'class' => 'CWebLogRoute',
                    // 'categories' => 'test.*',
                    'levels'=>'info, warning',
                    'showInFireBug'=>true,
                    'ignoreAjaxInFireBug' => true,
                ),
                array(
                    'class' => 'CWebLogRoute',
                    'levels'=>'info, warning',
                    // 'categories'=>'test.*',
                ),
                array( 
                   'class'=>'CProfileLogRoute', 
                   // 'levels' => CLogger::LEVEL_PROFILE, 
                   'levels'=>'trace',  //级别为trace 
                   'showInFireBug' => true, 
                   'ignoreAjaxInFireBug' => true, 
                   'categories' => 'system.db.* ', //只记录db的操作日志,其他的忽略 
                ),
                array( 
                    'class'=>'CFileLogRoute', 
                    'levels'=>'trace',  //级别为trace 
                    'categories' => 'system.db.* ', //只记录db的操作日志,其他的忽略 
                    'logFile'=>'db.log', 
                ),
                // uncomment the following to show log messages on web pages
                /*
                array(
                    'class'=>'CWebLogRoute',
                ),
                */
            ),

  • 3、使用事例
        Yii::beginProfile('db', 'example2'); 
        for($i=0;$i<10;$i++){ 
            // $Test = Test::model()->findByPk("1");
            $result = Yii::app()->db_mysql->createCommand("select * from Lang")->queryAll();
        } 
        Yii::endProfile('db', 'example2'); 
        echo 'done';
        Yii::trace('example trace message','example1'); 
        Yii::log("dfdf",CLogger::LEVEL_INFO,"example"); 
        Yii::log('test','info','system.test');

        Yii::beginProfile('db', 'example4'); 
        for($i=0;$i<10;$i++){ 
            $Test = Test::model()->findByPk("1");
            // $result = Yii::app()->db_mysql->createCommand("select * from test")->queryAll();
        } 
        Yii::endProfile('db', 'example4'); 

相关文章

  • YII1日志功能的使用

    1、在项目根目录下的index.php配置如下: 2、在protected/config/main.php配置如下...

  • 阿里云DDoS高防 - 访问与攻击日志实时分析(三)

    摘要:本文介绍了DDoS日志分析功能的日志报表的使用方法。 概述 本文介绍DDoS日志分析功能的日志报表的使用方法...

  • MyBatis实现日志

    一.日志 Mybatis 通过使用内置的日志工厂提供日志功能。内置日志工厂将会把日志工作委托给下面的实现之一:SL...

  • 日志记录框架

    版本 v1.0.0已完成:业务日志、通用日志、错误日志可以正常使用待完善:Action日志当前页面功能、本地存储的...

  • 三、日志(2)

    3、SpringBoot日志关系 SpringBoot使用它来做日志功能; 底层依赖关系 总结: ​ 1)、S...

  • 简单的 Golang 多色日志包

    比较简约的多色日志包,没有特别多的功能,仅提供在终端输出彩色日志的功能。 使用 在go.mod文件中添加log包:...

  • python 日志记录logging模块使用

    最近想在python flask项目中使用日志功能,于是想到了python自带的日志模块logging. 在学习这...

  • 2020-01-02

    MLogger 固件端日志模块 功能 通过串口将日志信息发送到PC,支持多级日志信息和格式化输出。 如何使用 引入...

  • NS3 日志使用

    介绍 NS3提供了功能强大的日志系统,利用日志我们可以方便的使用、调试NS3代码。并且NS3的日志系统使用起来也非...

  • Intellij Idea - git annotate功能显示

    在使用idea进行功能开发的时候,我们有时候需要使用git的annotate功能来查看代码变更日志。 下图为ann...

网友评论

      本文标题:YII1日志功能的使用

      本文链接:https://www.haomeiwen.com/subject/jxfwattx.html