2013-09-30 55 views
2

我想在我的網站上處理錯誤。我在日誌文件中記錄每個錯誤,但我想知道如何自定義記錄在日誌文件中的消息。如何在Yii Framework上自定義日誌文件?

現在,我得到這個消息:

2013年9月30日10時08分59秒[錯誤] [exception.CException]例外 '了CException' 在 myDomain的消息 '錯誤測試' .com \ protected \ controllers \ SiteController.php:234

你能幫我嗎?

+0

你可以使用Yii :: log($ message,$ level,$ category); –

+0

謝謝你的回答,但我還有其他問題。你如何刪除「堆棧跟蹤」? – Florent

+0

我認爲你可以在'index.php'文件中修改'defined('YII_TRACE_LEVEL')或者定義('YII_TRACE_LEVEL',3)'這行'' –

回答

2

對於手動定製日誌消息,您需要創建自己的LogRoute類。在你的情況,你需要從CFileLogRoute繼承類並重寫方法formatLogMessage(例如如在):

class MyFileLogRoute extends CFileLogRoute{ 
    protected function formatLogMessage($message,$level,$category,$time) 
    { 
     //enter code here your custom message format 
     return @date('Y/m/d H:i:s',$time)." [$level] [$category] $message\n"; 
    } 
} 

比配置您的配置文件:

 'log' => array(
      'class' => 'CLogRouter', 
      'routes' => array(
       array(
        'class' => 'MyFileLogRoute', 
        'levels' => 'error, warning, info', 
        'categories' => 'application.*', 
        'logPath' => dirname(__FILE__).'/../../../../../logs/', 
       ), 
       ... 

是的,@ragingprodigy是對的:您可以在index.php中設置0​​或define('YII_TRACE_LEVEL', 0)以刪除堆棧跟蹤f ROM日誌消息