0

我正在使用 kohana 3 上的网站构建,实际上我开始使用 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

1 回答 1

4

只需将日志常量用于消息类型,例如

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

因为这些反映了 PHP 中的错误类型。

PS 不需要调用 Log::write(),它会在关机时自动完成。

于 2012-04-04T14:22:25.610 回答