Welcome Guest, Not a member yet? Register   Sign In
[Solved]Best way for query logging
#8

[eluser]n0xie[/eluser]
Doh, I forgot all about $this->db->queries :ohh:

The addition of Hooks would add a small overhead (memory mostly), but would be minimal if you add the hook as a post_system hook. This way the output is already send to the client, so an user wouldn't notice the difference.

Since I liked the idea of storing all executed queries I made a POC:

Code:
/* hooks.php */
/* Location: ./system/application/config/hooks.php */
$hook['post_system'][] = array(
                                'class'    => 'DBlog_Hook',
                                'function' => 'log_all_query',
                                'filename' => 'DBlog_Hook.php',
                                'filepath' => 'hooks'
                                );

/* DBlog_Hook.php */
/* Location: ./system/application/hooks/DBlog_Hook.php */
class DBlog_Hook {

   var $path    = 'system/logs/';
    
    function DBlog_Hook()
    {
        $this->CI =& get_instance();
    }
    
    function log_all_query()
    {
        $dbs    = array();
        $output = NULL;
        
        $queries = $this->CI->db->queries;

        if (count($queries) == 0)
        {
            $output .= "no queries\n";
        }
        else
        {
            foreach ($queries as $query)
            {
                $output .= $query . "\n";
            }
            $output .= "===\n";
        }

        $this->CI->load->helper('file');
        if ( ! write_file($this->path . 'queries.txt', $output, 'a+'))
        {
             log_message('debug','Unable to write the file');
        }
    }
}


Messages In This Thread
[Solved]Best way for query logging - by El Forum - 10-16-2009, 01:44 AM
[Solved]Best way for query logging - by El Forum - 10-16-2009, 02:52 AM
[Solved]Best way for query logging - by El Forum - 10-16-2009, 03:02 AM
[Solved]Best way for query logging - by El Forum - 10-16-2009, 03:35 AM
[Solved]Best way for query logging - by El Forum - 10-16-2009, 04:45 AM
[Solved]Best way for query logging - by El Forum - 10-16-2009, 05:52 AM
[Solved]Best way for query logging - by El Forum - 10-16-2009, 06:36 AM
[Solved]Best way for query logging - by El Forum - 10-16-2009, 07:18 AM
[Solved]Best way for query logging - by El Forum - 10-16-2009, 07:58 AM
[Solved]Best way for query logging - by El Forum - 06-15-2010, 10:09 AM



Theme © iAndrew 2016 - Forum software by © MyBB