2012-04-04 76 views
0

我使用站點基礎上的Kohana 3,其實我開始使用Kohana的。 我想使用簡單的日誌記錄來查找錯誤。 我在不同的事情上從應用程序路徑中得到日誌目錄中的錯誤,我嘗試添加一個自己的錯誤。Kohana的日誌 - 寫錯誤

我這樣做:

Kohana::$log->add('error', 'Could not locate user'); 
Kohana::$log->write(); 

最後一行我得到這個錯誤後:

ErrorException [ Notice ]: Undefined index: error 

SYSPATH\classes\kohana\log\file.php [ 91 ] 

86 
87  foreach ($messages as $message) 
88  { 
89   // Write each message into the log file 
90   // Format: time --- level: body 
91   file_put_contents($filename, PHP_EOL.$message['time'].' --- '.$this->_log_levels[$message['level']].': '.$message['body'], FILE_APPEND); 
92  } 
93 } 
94 
95 } // End Kohana_Log_File 
SYSPATH\classes\kohana\log\file.php [ 91 ] » Kohana_Core::error_handler(arguments) 

SYSPATH\classes\kohana\log.php [ 184 ] » Kohana_Log_File->write(arguments) 

APPPATH\classes\controller\main.php [ 23 ] » Kohana_Log->write() 

{PHP internal call} » Controller_Main->action_index() 

SYSPATH\classes\kohana\request\client\internal.php [ 118 ] » ReflectionMethod->invoke(arguments) 

SYSPATH\classes\kohana\request\client.php [ 64 ] » Kohana_Request_Client_Internal->execute_request(arguments) 

SYSPATH\classes\kohana\request.php [ 1138 ] » Kohana_Request_Client->execute(arguments) 

DOCROOT\index.php [ 109 ] » Kohana_Request->execute() 

有什麼不對呢? 由於

回答

4

只要使用用於消息類型,例如日誌常數

Kohana::$log->add(Log::ERROR, 'Could not locate user');

,因爲這些反映了PHP錯誤類型。

P.S.沒有必要調用Log :: write(),它在關閉時自動完成。