1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
\r
5 * An open source application development framework for PHP 4.3.2 or newer
\r
7 * @package CodeIgniter
\r
8 * @author ExpressionEngine Dev Team
\r
9 * @copyright Copyright (c) 2008, EllisLab, Inc.
\r
10 * @license http://codeigniter.com/user_guide/license.html
\r
11 * @link http://codeigniter.com
\r
12 * @since Version 1.0
\r
16 // ------------------------------------------------------------------------
\r
21 * @package CodeIgniter
\r
22 * @subpackage Libraries
\r
24 * @author ExpressionEngine Dev Team
\r
25 * @link http://codeigniter.com/user_guide/general/errors.html
\r
30 var $_threshold = 1;
\r
31 var $_date_fmt = 'Y-m-d H:i:s';
\r
32 var $_enabled = TRUE;
\r
33 var $_levels = array('ERROR' => '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4');
\r
42 $config =& get_config();
\r
44 $this->log_path = ($config['log_path'] != '') ? $config['log_path'] : BASEPATH.'logs/';
\r
46 if ( ! is_dir($this->log_path) OR ! is_really_writable($this->log_path))
\r
48 $this->_enabled = FALSE;
\r
51 if (is_numeric($config['log_threshold']))
\r
53 $this->_threshold = $config['log_threshold'];
\r
56 if ($config['log_date_format'] != '')
\r
58 $this->_date_fmt = $config['log_date_format'];
\r
62 // --------------------------------------------------------------------
\r
67 * Generally this function will be called using the global log_message() function
\r
70 * @param string the error level
\r
71 * @param string the error message
\r
72 * @param bool whether the error is a native PHP error
\r
75 function write_log($level = 'error', $msg, $php_error = FALSE)
\r
77 if ($this->_enabled === FALSE)
\r
82 $level = strtoupper($level);
\r
84 if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold))
\r
89 $filepath = $this->log_path.'log-'.date('Y-m-d').EXT;
\r
92 if ( ! file_exists($filepath))
\r
94 $message .= "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n";
\r
97 if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE))
\r
102 $message .= $level.' '.(($level == 'INFO') ? ' -' : '-').' '.date($this->_date_fmt). ' --> '.$msg."\n";
\r
104 flock($fp, LOCK_EX);
\r
105 fwrite($fp, $message);
\r
106 flock($fp, LOCK_UN);
\r
109 @chmod($filepath, FILE_WRITE_MODE);
\r
116 /* End of file Log.php */
\r
117 /* Location: ./system/libraries/Log.php */