Codeigniter query times and custom file logging

∥☆過路亽.° 提交于 2019-12-03 15:14:17

问题


I'm developing an app using Codeigniter 1.7.3 (yes, I know there's a new version, but I'm just too lazy to update).

I noticed the Codeigniter built-in profiler outputs the query times. I want to access those times and write a custom log file with each query and each query time. To access the query I can user $this->db->last_query().

Is there any way to access those query times without hacking the core? Is there any library to write logs besides the system logs Codeigniter blundles?

Thanks!


回答1:


Well, I figure it out. I've set a hook just like this:

//config/hooks.php

$hook['display_override'][] = array(
        'class' => '',
        'function' => 'log_queries',
        'filename' => 'log_queries.php',
        'filepath' => 'hooks'
);

//hooks/log_queries.php

function log_queries() {
    $CI =& get_instance();
    $times = $CI->db->query_times;
    foreach ($CI->db->queries as $key=>$query) {
        log_message('debug', "Query: ".$query." | ".$times[$key]);
    }
}

I hope it helps someone!




回答2:


Can't help with the CodeIgniter side of things, but regarding logging, log4php is good: http://logging.apache.org/log4php/



来源:https://stackoverflow.com/questions/5444883/codeigniter-query-times-and-custom-file-logging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!