CI_Log Class Reference

List of all members.


Public Member Functions

 CI_Log ()
 Constructor.
 write_log ($level= 'error', $msg, $php_error=FALSE)
 Write Log File.

Public Attributes

 $log_path
 $_threshold = 1
 $_date_fmt = 'Y-m-d H:i:s'
 $_enabled = TRUE
 $_levels = array('ERROR' => '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4')

Detailed Description

Definition at line 27 of file Log.php.


Member Function Documentation

CI_Log::CI_Log (  ) 

Constructor.

public

Definition at line 40 of file Log.php.

References $config, get_config(), and is_really_writable().

00041         {
00042                 $config =& get_config();
00043                 
00044                 $this->log_path = ($config['log_path'] != '') ? $config['log_path'] : BASEPATH.'logs/';
00045                 
00046                 if ( ! is_dir($this->log_path) OR ! is_really_writable($this->log_path))
00047                 {
00048                         $this->_enabled = FALSE;
00049                 }
00050                 
00051                 if (is_numeric($config['log_threshold']))
00052                 {
00053                         $this->_threshold = $config['log_threshold'];
00054                 }
00055                         
00056                 if ($config['log_date_format'] != '')
00057                 {
00058                         $this->_date_fmt = $config['log_date_format'];
00059                 }
00060         }

Here is the call graph for this function:

CI_Log::write_log ( level = 'error',
msg,
php_error = FALSE 
)

Write Log File.

Generally this function will be called using the global log_message() function

public

Parameters:
string the error level
string the error message
bool whether the error is a native PHP error
Returns:
bool

Definition at line 75 of file Log.php.

00076         {               
00077                 if ($this->_enabled === FALSE)
00078                 {
00079                         return FALSE;
00080                 }
00081         
00082                 $level = strtoupper($level);
00083                 
00084                 if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold))
00085                 {
00086                         return FALSE;
00087                 }
00088         
00089                 $filepath = $this->log_path.'log-'.date('Y-m-d').EXT;
00090                 $message  = '';
00091                 
00092                 if ( ! file_exists($filepath))
00093                 {
00094                         $message .= "<"."?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n";
00095                 }
00096                         
00097                 if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE))
00098                 {
00099                         return FALSE;
00100                 }
00101 
00102                 $message .= $level.' '.(($level == 'INFO') ? ' -' : '-').' '.date($this->_date_fmt). ' --> '.$msg."\n";
00103                 
00104                 flock($fp, LOCK_EX);    
00105                 fwrite($fp, $message);
00106                 flock($fp, LOCK_UN);
00107                 fclose($fp);
00108         
00109                 @chmod($filepath, FILE_WRITE_MODE);             
00110                 return TRUE;
00111         }


Member Data Documentation

CI_Log::$_date_fmt = 'Y-m-d H:i:s'

Definition at line 31 of file Log.php.

CI_Log::$_enabled = TRUE

Definition at line 32 of file Log.php.

CI_Log::$_levels = array('ERROR' => '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4')

Definition at line 33 of file Log.php.

CI_Log::$_threshold = 1

Definition at line 30 of file Log.php.

CI_Log::$log_path

Definition at line 29 of file Log.php.


The documentation for this class was generated from the following file: