Welcome Guest, Not a member yet? Register   Sign In
Log core error messages in database
#3

[eluser]ilumos[/eluser]
So I've extended the log library and I'm met with this error:

Code:
Fatal error: Class 'CI_Controller' not found in /Users/ilumos/Sites/lanager/system/core/CodeIgniter.php on line 233

I'm using modular extensions.

Here's my /application/libraries/MY_Log.php


Code:
class MY_Log extends CI_Log
{

/*
public function __construct()
{
  parent::__construct();
}
*/


function log($category, $severity, $message, $data = NULL, $file = '', $line = '')
{
  $CI =& get_instance(); // commenting this fixes everything
  //$CI->load->helper('session');
  //$user_id = get_user_id();
  $user_id = 0;
  $ip = $_SERVER['REMOTE_ADDR'];
  
  // only backtrace non-core errors which have no file/line specified
  if($category != 'core' && (empty($file) OR empty($line))) {
   // find out where the log request was called from
   $backtrace = debug_backtrace();
   $line = $backtrace[0]['line'];
   $file = $backtrace[0]['file'];
   $file = strstr($file,'/application');
  }

  if(is_array($data))
  {
   $data = print_r($data,TRUE);
  }
  $insert_data = array(
   'category' => $category,
   'severity' => $severity,
   'message' => $message,
   'data' => $data,
   'user_id' => $user_id,
   'ip' => $ip,
   'file' => $file,
   'line' => $line,
  );
  
  //$log_to_db = $CI->db->insert('usage', $insert_data);
  
  if($log_to_db = TRUE)
  {
   return TRUE;
  }
  else // if logging to database fails, fall back to file logging
  {
   $message = $message.' user_id:'.$user_id.' ip:'.$ip.' file:'.$file.' line:'.$line.' data:'.print_r($data, TRUE);
   $log_to_file = $this->log_to_file($severity,$message);
   return $log_to_file;
  }

}

function log_browser()
{
  //$CI =& get_instance();
}



public function write_log($level = 'error', $msg, $php_error = FALSE)
{
  if ($this->_enabled === FALSE)
  {
   return FALSE;
  }

  $level = strtoupper($level);

  if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold))
  {
   return FALSE;
  }
  
  $this->log('core',$level,$msg,NULL); // hijack message about to be logged

  return TRUE;
}


function log_to_file($level = 'error', $msg)
{
  if ($this->_enabled === FALSE)
  {
   return FALSE;
  }

  $level = strtoupper($level);

  if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold))
  {
   return FALSE;
  }

  $filepath = $this->_log_path.'log-'.date('Y-m-d').'.php';
  $message  = '';

  if ( ! file_exists($filepath))
  {
   $message .= "<"."?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n";
  }

  if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE))
  {
   return FALSE;
  }

  $message .= $level.' '.(($level == 'INFO') ? ' -' : '-').' '.date($this->_date_fmt). ' --&gt; '.$msg."\n";

  flock($fp, LOCK_EX);
  fwrite($fp, $message);
  flock($fp, LOCK_UN);
  fclose($fp);

  @chmod($filepath, FILE_WRITE_MODE);
  return TRUE;
}


}

(I've commented all references to $CI as this seems to be the culprit.

I seem to be having the same problem as this guy:

http://stackoverflow.com/questions/88788...-not-found

Any help appreciated

Thanks


Messages In This Thread
Log core error messages in database - by El Forum - 07-18-2012, 11:41 PM
Log core error messages in database - by El Forum - 07-19-2012, 12:00 AM
Log core error messages in database - by El Forum - 07-22-2012, 12:00 PM
Log core error messages in database - by El Forum - 07-22-2012, 10:22 PM
Log core error messages in database - by El Forum - 07-23-2012, 12:30 AM
Log core error messages in database - by El Forum - 07-23-2012, 12:41 PM
Log core error messages in database - by El Forum - 07-23-2012, 01:02 PM
Log core error messages in database - by El Forum - 07-23-2012, 02:03 PM
Log core error messages in database - by El Forum - 07-23-2012, 06:12 PM
Log core error messages in database - by El Forum - 07-23-2012, 07:39 PM
Log core error messages in database - by El Forum - 09-23-2012, 05:14 AM
Log core error messages in database - by El Forum - 09-23-2012, 10:23 AM
Log core error messages in database - by El Forum - 10-29-2012, 03:38 PM



Theme © iAndrew 2016 - Forum software by © MyBB