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