Codeigniter查询时间和自定义文件记录 [英] Codeigniter query times and custom file logging

查看:112
本文介绍了Codeigniter查询时间和自定义文件记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Codeigniter 1.7.3开发应用程序(是的,我知道有一个新版本,但是我懒得更新).

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).

我注意到Codeigniter内置的探查器输出查询时间.我想访问这些时间,并为每个查询和每个查询时间编写一个自定义日志文件.要访问查询,我可以使用$ this-> db-> last_query().

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().

有没有办法在不破坏内核的情况下访问那些查询时间? 除了系统日志Codeigniter钝器之外,是否还有其他库可以写日志?

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?

谢谢!

推荐答案

好吧,我知道了.我已经像这样设置了一个钩子:

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!

这篇关于Codeigniter查询时间和自定义文件记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆