Log クラス

The log class allows you to write messages to the log files.

設定

The log files are being placed in the folder specified by the attribute 'log_path' in the config.php. You can also set the 'log_threshold' and the 'log_date_format' parameters there.
These settings can also be changed on the fly by using the Config Class.

パラメータ 規定値 説明
log_threshold constant
Fuel::L_WARNING
Can be any of the following: Fuel::L_NONE, Fuel::L_ERROR, Fuel::L_WARNING, Fuel::L_DEBUG, Fuel::L_INFO or Fuel::L_ALL
log_path string
APPPATH.'logs/'
Where to put the log files. (Folder must be writable)
log_date_format string
'Y-m-d H:i:s'
The date format for the log entries. This format must follow the PHP date format rules. See http://www.php.net/date for a complete list.

使用方法

There are four predefined functions for ease of use:

Log::info()
Log::debug()
Log::warning()
Log::error()

They all use the main function Log::write() which requires the $level parameter as the first argument.

Some examples:
// Write a log entry with the level "Info" to the log file for the current day
$var = 1;
Log::info('Application started (with $var = '.$var.')', 'my_init_function()');

// Save the new value of $var to the log file, without the $method parameter
$var = 5;
Log::debug('$var is now '.$var);

// Send a warning log entry
if($var !== 1) Log::warning('Although $var has been changed, we will keep going.');

// Send an error log entry
if($var !== 1) Log::error('We cannot keep going, $var has been changed! :o');

// Finally, create a log entry with a custom $level
Log::write('Link', 'More info on http://fuelphp.com/');
Output

All log files are being placed in the defined folder (see above), composed in folders named by the current year followed by the month ("2011/06" for example) with the day of the month as the filename ("15.php" for example).
The complete path to our example log file would be: APPPATH.'logs/2011/06/15.php'

The examples above would write the following code to the log file:

<?php defined('COREPATH') or exit('No direct script access allowed'); ?>

Info - 2011-01-03 18:44:45 --> my_init_function() - Application started (with $var = 1)
Debug - 2011-01-03 18:44:45 --> $var is now 5
Warning - 2011-01-03 18:44:45 --> Although $var has been changed, we will keep going.
Error - 2011-01-03 18:44:45 --> We cannot keep going, $var has been changed! :o
Link - 2011-01-03 18:44:45 --> More info on http://fuelphp.com/

info($msg, $method = null)

The info method allows you to write a log entry with the $level "Info".

静的 はい
パラメータ
パラメータ 規定値 説明
$msg 必須 The message for the info log entry.
$method
null
Information about the method which created the log entry.
返り値 boolean
$var = 1;
Log::info('Application started (with $var = '.$var.')', 'my_init_function()');

debug($msg, $method = null)

The debug method allows you to write a log entry with the $level "Debug".

静的 はい
パラメータ
パラメータ 規定値 説明
$msg 必須 The message for the info log entry.
$method
null
Information about the method which created the log entry.
返り値 boolean
$var = 5;
Log::debug('$var is now '.$var);

warning($msg, $method = null)

The warning method allows you to write a log entry with the $level "Warning".

静的 はい
パラメータ
パラメータ 規定値 説明
$msg 必須 The message for the info log entry.
$method
null
Information about the method which created the log entry.
返り値 boolean
// we send a warning log entry
if($var !== 1) Log::warning('Although $var has been changed, we will keep going.');

error($msg, $method = null)

The error method allows you to write a log entry with the $level "Error".

静的 はい
パラメータ
パラメータ 規定値 説明
$msg 必須 The message for the info log entry.
$method
null
Information about the method which created the log entry.
返り値 boolean
// we send an error log entry
if($var !== 1) Log::error('We cannot keep going, $var has been changed! :o');

write($level, $msg, $method = null)

The write method allows you to write a log entry with a custom $level.

静的 はい
パラメータ
パラメータ 規定値 説明
$level 必須 A custom Level.
$msg 必須 The message for the info log entry.
$method
null
Information about the method which created the log entry.
返り値 boolean
// and finally, we create a log entry with a custom $level
Log::write('Link', 'More info on http://fuelphp.com/')

Procedural helpers

logger($level, $msg, $method = null)

The logger function is an alias for Log::write.

パラメータ
パラメータ 規定値 説明
$level 必須 A custom Level.
$msg 必須 The message for the info log entry.
$method
null
Information about the method which created the log entry.
返り値 void
logger(\Fuel::L_INFO, 'My Message', 'SomeMethod');