Welcome Guest, Not a member yet? Register   Sign In
logging to a database
#5

[eluser]Billy Shall[/eluser]
Ended up taking the simple route on this:

Code:
class MY_Log extends CI_Log {
    
    function __construct()
    {
        parent::CI_Log();
        
        $config =& get_config();
        
        if (is_numeric($config['log_threshold']))
        {
            $this->_threshold = $config['log_threshold'];
        }
    }

    function write_log($level = 'error', $msg, $php_error = FALSE)
    {        
        $level = strtoupper($level);
        
        if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold))
        {
            return FALSE;
        }

        $time = time();
        $ip = $this->get_ip_address();
        
        //Log Error To Database
        require(APPPATH.'config/database.php');

        mysql_connect($db['default']['hostname'], $db['default']['username'], $db['default']['password'])
            or die(mysql_error());
        
        mysql_select_db($db['default']['database'])
            or die(mysql_error());
        
        mysql_query("
            INSERT INTO errors (error_level, error_msg, error_time, error_ip_address)
            VALUES('$level', '$msg', '$time', '$ip')")
            or die(mysql_error());  
        
        mysql_close();
        
        return TRUE;
    }
    
    function get_ip_address()
    {
        if (!empty($_SERVER['HTTP_CLIENT_IP']))
        {
            $ip =  $_SERVER['HTTP_CLIENT_IP'];
        }
        elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
        {
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        }
        elseif (!empty($_SERVER['REMOTE_ADDR']))
        {
            $ip = $_SERVER['REMOTE_ADDR'];
        }
        else
        {
            $ip = NULL;
        }        
        return $ip;
    }
}


Messages In This Thread
logging to a database - by El Forum - 05-26-2010, 06:02 PM
logging to a database - by El Forum - 05-26-2010, 08:30 PM
logging to a database - by El Forum - 05-27-2010, 03:40 PM
logging to a database - by El Forum - 05-27-2010, 05:31 PM
logging to a database - by El Forum - 10-16-2010, 11:50 AM
logging to a database - by El Forum - 10-16-2010, 01:14 PM
logging to a database - by El Forum - 10-16-2010, 01:17 PM
logging to a database - by El Forum - 10-17-2010, 07:19 AM



Theme © iAndrew 2016 - Forum software by © MyBB