快速理解與運用Yii 日誌

來源:互聯網
上載者:User

標籤:yii 日誌   yii入門 yii入門實踐  yii架構   資料庫追蹤   php yii   

  1. 將日誌記錄到文本中.

          Yii::log("test");  //寫入測試日誌

    //找到設定檔 component->log 'log'=>array(    'class'=>'CLogRouter',    'routes'=>array(        array(            'class'=>'CFileLogRoute',            'levels'=>'warning,error,info’ ,         ),


  2. 將指定的categories下的日誌,寫入到指定的檔案夾中
    Yii::log("test my cate" ,  CLogger::LEVEL_INFO , "debug");

    'log'=>array(    'class'=>'CLogRouter',    'routes'=>array(        //...        array(            'class'=>'CFileLogRoute',            'levels'=>'info,trace',            'categories'=> 'debug.*',            'logFile'=> date("Y-m-d").'debug.log',          ),

  3. 將日誌寫入到firebug console 中去.// chorme console 也可以用
    Yii::log("test in console" ,  CLogger::LEVEL_INFO , "debug");
    'log'=>array(    'class'=>'CLogRouter',    'routes'=>array(        array(            'class'=>'CWebLogRoute',            'categories'=>'debug',            'levels'=>'info,trace',            'showInFireBug'=>true,        ),

  4. 追蹤SQL 查詢.
    4.1 首先調整db  r s

    首先,將db 的配置調整。

    'db'=>array(      //....            'enableParamLogging'=>true,           ),


    一段執行sql 的語句。
    $cmd = Yii::app()->db->createCommand();$sql = "select id,username from {{users}} limit 5 ";$cmd->setText($sql);$rows = $cmd->queryAll();


    //日誌配置。

    'log'=>array(    'class'=>'CLogRouter',    'routes'=>array(        array(            'class'=>'CFileLogRoute',            'categories'=>'system.db.CDbCommand.*,            'logFile'=> date("Y-m-d").'db.log',        ),



    同理,如果需要將日誌寫入firebug ,配置調整為即可.

    'log'=>array(    'class'=>'CLogRouter',    'routes'=>array(        array(            'class'=>'CWebLogRoute',            'categories'=>'system.db.CDbCommand.*,            'showInFireBug'=>true,        ),




  5. 直接在頁面上查看資料庫查詢.

    5.1 db 配置設enableProfile 為true.  同四。
    配置如下。

    'log'=>array(    'class'=>'CLogRouter',    'routes'=>array(        array(            'class' => 'CProfileLogRoute',            'levels'=>'profile,info,trace,warning,error',        ),

    去行查詢後。[使用4的查詢] 結果如。



  6. 查看程式段中的運行效能.

    配置和5一樣。

    Yii::beginProfile("t1");    for( $i=0;$i<100000;$i++) { $t = $i;}Yii::endProfile("t1");



  7. 如果希望日誌追蹤的更詳細,

    //進入 index.php 將debug 開啟 defined('YII_DEBUG') or define('YII_DEBUG',true);



  8. 使用第三方外掛程式.

    8.1 去官網下載代碼.

    http://www.yiiframework.com/extension/yii-debug-toolbar/

    放入 extensions 目錄下
    添加配置。

    'log'=>array(    'class'=>'CLogRouter',    'routes'=>array(        array(            'class'=>'ext.yii-debug-toolbar.YiiDebugToolbarRoute',                        'ipFilters'=>array('192.168.1.*'),        ),


    調整資料庫配置。
    'db'=>array(//...            'enableProfiling'=>true,            'enableParamLogging'=>true,           ),






著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

快速理解與運用Yii 日誌

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.