是否有一个漂亮的打印堆栈转储? [英] Is there a Pretty Print stack dump?

查看:147
本文介绍了是否有一个漂亮的打印堆栈转储?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们面对它, debug_backtrace()输出不是很漂亮。有没有人编写一个包装器?



你最喜欢的是$ code var_dump()(可用于商业项目,所以没有GPL(虽然LGPL可以))



另请参见:,如语法着色:





编辑:



在商业项目中包含Xdebug。



Xdebug许可证只有几个术语,看起来很宽容。



Xdebug是一个C扩展名。因此,在项目中重新分配或部分内容可能会有些困难。根据您的要求,我看到几个选项:




  • 让您的最终用户从Linux发行版或站点的DLL安装Xdebug

  • 为所有支持的平台分发.dll和.so文件

  • 让您的最终用户构建源代码

  • 分发PHP的自定义构建


Let's face it, debug_backtrace() output is not very pretty. Did anyone code a wrapper?

And what's your favourite pretty var_dump() (which is usable in commercial projects, so no GPL (although LGPL is ok))

See also: A more pretty/informative Var_dump alternative in PHP?


Six years - and ten thousand views of this question - later, and I am still using this. It isn't pretty in a way that looks good on screen, like Kint (which is excellent).

It is plain text, which I can email to myself in in automated error reports and can display in the browser's developer console using ChromePhp.

/**
 * @brief Returns an HTML formatted string showing details of the backtrace
 * 
 * Example:
 * 
 *    F:\Dropbox\programs\Xampp\htdocs\api\q.php:48 e(373, 'beer', 'curry')
 *    F:\Dropbox\programs\Xampp\htdocs\api\q.php:53 d(26366, 28255, 8364)
 *    F:\Dropbox\programs\Xampp\htdocs\api\q.php:58 c()
 *    F:\Dropbox\programs\Xampp\htdocs\api\q.php:63 b(1283, 15488, 29369)
 *    F:\Dropbox\programs\Xampp\htdocs\api\q.php:72 a(788, 6077, 25010)
 */
function FormatBacktrace()
{
    $result = '<h4>Backtrace</h4>';

    foreach (debug_backtrace() as $trace)
    {
        if ($trace['function'] ==__FUNCTION__)
            continue;

            $parameters = '';
            foreach ($trace['args'] as $parameter)
                $parameters .= $parameter . ', ';

                if (substr($parameters, -2) == ', ')
                    $parameters = substr($parameters, 0, -2);

                    if (array_key_exists('class', $trace))
                        $result .= sprintf("%s:%s %s::%s(%s)<br>", $trace['file'], $trace['line'],  $trace['class'], $trace['function'],  $parameters);
                    else
                        $result .= sprintf("%s:%s %s(%s)<br>", $trace['file'], $trace['line'], $trace['function'], $parameters);
    }

    return $result;
}

解决方案

The Xdebug extension can print stacktraces with a configurable degree of verbosity.

It also offers some additional var_dump() features such as syntax coloring:

Edit:

Regarding the inclusion of Xdebug in a commercial project.

The Xdebug license has only a few terms and seems pretty permissive.

Xdebug is a C extension. As such re-distributing it or part of it in your project may be somewhat difficult. Depending on your requirements I see a few options:

  • Have your end user install Xdebug from a Linux distribution package or a DLL from the site
  • Distribute .dll and .so files for all supported platforms
  • Have your end user build the source code
  • Distribute a custom build of PHP

这篇关于是否有一个漂亮的打印堆栈转储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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