1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
5 * An open source application development framework for PHP 5.1.6 or newer
8 * @author ExpressionEngine Dev Team
9 * @copyright Copyright (c) 2008 - 2011, 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
30 protected $_threshold = 1;
31 protected $_date_fmt = 'Y-m-d H:i:s';
32 protected $_enabled = TRUE;
33 protected $_levels = array('ERROR' => '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4');
38 public function __construct()
40 $config =& get_config();
42 $this->_log_path = ($config['log_path'] != '') ? $config['log_path'] : APPPATH.'logs/';
44 if ( ! is_dir($this->_log_path) OR ! is_really_writable($this->_log_path))
46 $this->_enabled = FALSE;
49 if (is_numeric($config['log_threshold']))
51 $this->_threshold = $config['log_threshold'];
54 if ($config['log_date_format'] != '')
56 $this->_date_fmt = $config['log_date_format'];
60 // --------------------------------------------------------------------
65 * Generally this function will be called using the global log_message() function
67 * @param string the error level
68 * @param string the error message
69 * @param bool whether the error is a native PHP error
72 public function write_log($level = 'error', $msg, $php_error = FALSE)
74 if ($this->_enabled === FALSE)
79 $level = strtoupper($level);
81 if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold))
86 $filepath = $this->_log_path.'log-'.date('Y-m-d').EXT;
89 if ( ! file_exists($filepath))
91 $message .= "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n";
94 if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE))
99 $message .= $level.' '.(($level == 'INFO') ? ' -' : '-').' '.date($this->_date_fmt). ' --> '.$msg."\n";
102 fwrite($fp, $message);
106 @chmod($filepath, FILE_WRITE_MODE);
113 /* End of file Log.php */
114 /* Location: ./system/libraries/Log.php */