状态 草稿
Todo Proof read!
官方最后更新时间 2008/08/11 15:59

日志类

Note:

在 Kohana v2.2 已不推荐使用此类。现在其方法均放在了 Kohana 类

由于其方法均放在了 Kohana 类 类中,以下就不再进行翻译。

Configuration

The configuration file Log.php can be found in the application/config directory. If it's not there it can be copied from the system/config directory. See for more information on the 配置类(Config Class) page.

There are three settings for the Log class:

$config['threshold'] = 0;
 
$config['directory'] = 'logs';
 
$config['format'] = 'Y-m-d H:i:s';

$config['threshold'] can be set at four levels:

  • 0 - Logging is disabled
  • 1 - Error messages including PHP errors
  • 2 - Debug messages
  • 3 - Informational messages

When set to 3 it will also log 2 and 1. Same goes for 2.

Level 1 is recommended in production use as it will only log errors. Level 2 is useful while debugging, it will log all libraries loaded and any errors. Nothing is logged to level 3 by Kohana by default, but can be used for custom logging by applications.

Important setting the level to 2 or 3 can slow down your application significantly.

$config['directory'] log file directory, relative to application/, or absolute.

$config['format'] format for the timestamps according to date()

Kohana 2.2 makes a small change to the logging threshold order. levels 2 and 3 can be used without the overhead of debug. By default nothing is logged to level 2 or 3 by Kohana.
  • 0 - Logging is disabled
  • 1 - Error messages including PHP errors
  • 2 - Application Alert messages (changed level)
  • 3 - Application Information messages (changed level)
  • 4 - Debug messages (new level)

Methods

Adding entries to the log file

Log::add($type, $message) logs the message according to the type given (error,debug,info), the item will be preceded by a timestamp formatted according to $config['format'].

Log::add('error', 'Query went wrong'); // returns void
Log::add('debug', 'Custom library X loaded'); // returns void

Writing the log entries to the file

Log::write() is called by default on the shutdown event (event.shutdown). See for more information on events the 事件类(Event Class) page. There is typically no need to call it manually.

Log::write(); // returns void
core/log.txt · 最后更改: 2008/09/03 02:31 由 icyleaf