2012-04-04 77 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(),它在关闭时自动完成。