[eluser]Unknown[/eluser]
I would like to store system error log to a database by extending the existing CI_Log class. So far this is what i have done
Code:
class MY_Logger extends CI_Log{
public function __construct(){
parent::__construct();
}
function write_log($level='error', $msg, $php_error = FALSE){
$result = parent::write_log($level, $msg, $php_error);
$ci =& get_instance();
$ci->load->library('user_agent');
if ($result == TRUE && strtoupper($level) == 'ERROR') {
$gmtoffset = 60*60*5;
$post = array(
'log_type' => $level,
'log_message' => $msg,
'log_php_message' => $php_error,
'log_ip_origin' => $this->input->ip_address(),
'log_user_agent' => $this->agent->agent_string(),
'log_date' => date("Y-m-d H:i:s",time() + $gmtoffset)
);
$ci->db->insert('system_log', $post);
}
return $result;
}
}
and i have the following configured in autoload.php and config.php
$autoload['libraries'] = array('database', 'session', 'xmlrpc', 'user_agent');
$config['log_threshold'] = 1;
However when i test it, it does not store the error to database (although, it displays and writes the log properly)
Can any one point out what i missed here?
ps:
Having changed the code so it extends CI_Exceptions does not work as well:
Code:
class MY_Exceptions extends CI_Exceptions{
function __construct(){
parent::__construct();
}
function log_exception($severity, $message, $filepath, $line){
//$result = parent::write_log($level, $msg, $php_error);
$ci =& get_instance();
//if ($result == TRUE && strtoupper($level) == 'ERROR') {
$gmtoffset = 60*60*5;
$post = array(
'log_type' => $severity,
'log_message' => $message,
'log_php_message' => $line,
'log_ip_origin' => $ci->input->ip_address(),
'log_user_agent' => $ci->agent->agent_string(),
'log_date' => date("Y-m-d H:i:s",time() + $gmtoffset)
);
$ci->db->insert('system_log', $post);
//}
parent::log_exception($severity, $message, $filepath, $line);
//return $result;
}
}
and yes i also post this issue at stackoverflow here
http://stackoverflow.com/questions/16413...1_16413781