CI框架配置socketLog 远程调试

作者:matrix 被围观: 5,047 次 发布时间:2017-04-28 分类:零零星星 | 5 条评论 »

这是一个创建于 2549 天前的主题,其中的信息可能已经有所发展或是发生改变。

github: https://github.com/luofei614/SocketLog

socketLog是开发api的debug神器,可以在完全不影响客户端调用的时候debug数据,非常NICE.

添加Slog.php文件

下载github项目中的Slog.php到libraries目录

common_helper.php全局函数中添加代码

/**
 * CI框架 socketLog 远程调试
 *
 * 使用:
 * slog($this->db->last_query());
 *
 * chrome安装相关插件之后控制台就能看到相关数据
 *
 * @URL https://github.com/luofei614/SocketLog
 */
use think\org\Slog;
if (!function_exists('slog')) {
    function slog($log, $type = 'log', $css = '')
    {
        require_once APPPATH . 'libraries' . DIRECTORY_SEPARATOR . 'Slog.php'; #注意这里的载入路径,请确保是上一步的操作位置
        if (is_string($type)) {
            $type = preg_replace_callback('/_([a-zA-Z])/', create_function('$matches', 'return strtoupper($matches[1]);'), $type);
            if (method_exists('\think\org\Slog', $type) || in_array($type, Slog::$log_types)) {
                return call_user_func(array('\think\org\Slog', $type), $log, $css);
            }
        }
        if (is_object($type) && 'mysqli' == get_class($type)) {
            return Slog::mysqlilog($log, $type);
        }
        if (is_resource($type) && ('mysql link' == get_resource_type($type) || 'mysql link persistent' == get_resource_type($type))) {
            return Slog::mysqllog($log, $type);
        }
        if (is_object($type) && 'PDO' == get_class($type)) {
            return Slog::pdolog($log, $type);
        }
        throw new Exception($type . ' is not SocketLog method');
    }

    //配置参数加载
    slog(array(
        'enable'=>true,//是否打印日志的开关
        'host'=>'slog.thinkphp.cn',//websocket服务器地址,默认localhost
        'optimize'=>true,//是否显示利于优化的参数,如果运行时间,消耗内存等,默认为false
        'show_included_files'=>true,//是否显示本次程序运行加载了哪些文件,默认为false
        'error_handler'=>false,//是否接管程序错误,将程序错误显示在console中,默认为false
        'force_client_ids'=>array('xxx'),//日志强制记录到配置的client_id,默认为空
        'allow_client_ids'=>array('xxx')//限制允许读取日志的client_id,默认为空,表示所有人都可以获得日志。
    ),'config');
}

配置浏览器以及接收debug的客户端

此工具是TP开发人员编写,已经内置于TP5中。
此项功能需要有服务器提供websocket服务,为了避免不必要的折腾,TP也提供了公共服务:http://slog.thinkphp.cn

  1. 打开之后获取socketLog帐号的client_id,粘贴到上一步的配置参数加载中.

  2. 安装chrome 插件 SocketLog
    https://chrome.google.com/webstore/detail/apkmbfpihjhongonfcgdagliaglghcod

  3. SocketLog 插件配置

监听地址:ws://slog.thinkphp.cn:1229
Client_ID:上面setup1中复制的id

使用

php代码中需要debug的地方slog('data');
然后chrome任意页面 打开Console,当有请求执行到debug的地方控制台即可看到数据

图片3676-CI框架配置socketLog 远程调试

其他文章:
本文固定链接:https://www.hhtjim.com/the-ci-framework-configuration-socketlog-remote-debugging.html
matrix
本文章由 matrix 于2017年04月28日发布在零零星星分类下,目前没有通告,你可以至底部留下评论。
转载请注明:CI框架配置socketLog 远程调试-HHTjim'S 部落格
关键字:, ,

有5 条评论 »

  1. 苏红文创 苏红文创 2017-8-28 11:52:45 +0800#3

    羡慕程序员,我也曾经学过VB还有PHP。后来果断放弃,太难了。但是还好,简单的东西还能看懂和修改一些。

    • Matrix Matrix Moderator 2017-8-28 19:39:35 +0800

      别羡慕这个职业 很累,加班也普遍,我见过的除非做上游层

  2. 天津网站建设 天津网站建设 2017-8-10 15:26:46 +0800#2

    我不是程序员了,就是喜欢。没事会来看看博主的。。

  3. 站神 站神 2017-8-8 20:12:44 +0800#1

    我来也!博主难道是个技术猿嘛!!!

    • Matrix Matrix Moderator 2017-8-8 23:41:03 +0800

      技术假的。现在 程序员倒是真的

添加新评论 »

 🙈 😱 😂 😛 😭 😳 😀 😆 👿 😉 😯 😮 😕 😎 😐 😥 😡 😈 💡

插入图片

NOTICE: You should type some Chinese word (like “你好”) in your comment to pass the spam-check, thanks for your patience!