YII1日志功能的使用

2017-04-14  本文已影响107人  liamu
<?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();

        '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',
                ),
                */
            ),

        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'); 
上一篇 下一篇

猜你喜欢

热点阅读