Example #1
0
 public function __construct()
 {
     $config = Config::instance();
     // Check if logging is enabled. Default: enabled
     $this->_enabled = $config->item('log', 'enabled') !== null ? (bool) $config->item('log', 'enabled') : true;
     if ($this->_enabled) {
         // Assign a default log path if not specified in config
         $this->_log_path = $config->item('log', 'path') !== '' ? $config->item('log', 'path') : APPPATH . 'logs/';
         // Assign a default log extension if not specified in config
         $this->_file_ext = $config->item('log', 'file_extension') && $config->item('log', 'file_extension') !== '' ? ltrim($config->item('log', 'file_extension'), '.') : 'php';
         // Create the log directory if it doesn't exist
         file_exists($this->_log_path) or mkdir($this->_log_path, DIR_WRITE_MODE, true);
         // Wait what? We failed to create the directory. Abort!
         if (!is_dir($this->_log_path)) {
             Exception::trace('Could not create the logging directory');
         }
         if (is_numeric($config->item('log', 'threshold'))) {
             $this->_threshold = (int) $config->item('log', 'threshold');
         } elseif (is_array($config->item('log', 'threshold'))) {
             $this->_threshold = $this->_threshold_max;
             $this->_threshold_array = array_flip($config->item('log', 'threshold'));
         }
         if ($config->item('log', 'date_format') !== '') {
             $this->_date_fmt = $config->item('log', 'date_format');
         }
     }
 }