【问题标题】:How to change the colors of xdebug output?如何更改 xdebug 输出的颜色?
【发布时间】:2013-10-24 16:54:16
【问题描述】:

xdebug 的红色和黄色标准颜色会在几个小时后伤害您的眼睛。

http://www.designified.com/blog/article/76/restyling-xdebug-output 描述了如何用需要 jquery 的 javascript 替换样式。

我一直在寻找更直接的方法,终于找到了。

【问题讨论】:

    标签: php html css web xdebug


    【解决方案1】:

    有一个不错的 xdebug!

    是的,你可以。试试下面这个 css。

    table.xdebug-error {
      width: auto;
      background: white;
      border: none;
      border-spacing: none;
      border-collapse: collapse;
      box-shadow: 0px 3px 10px 0px black;
      position: fixed;
      top: 0px;
      right: 0px;
      z-index: 8888;
      font: 14px verdana;
      transform-origin: top right;
      transform: scaleX(0.4);
      opacity: 0.3;
      transition: all 200ms ease;
    }
    table.xdebug-error caption,
    table.xdebug-error th,
    table.xdebug-error td {
      text-align: left;
      vertical-align: middle;
    }
    table.xdebug-error a img {
      border: 0;
    }
    table.xdebug-error :focus {
      outline: 0;
    }
    table.xdebug-error pre {
      margin: 0;
    }
    table.xdebug-error tbody tr td,
    table.xdebug-error tbody tr th {
      border: none;
      border-bottom: 1px solid rgba(0,0,0,0.2);
      font-weight: normal;
    }
    table.xdebug-error tbody tr td {
      padding: 3px !important;
      vertical-align: top;
    }
    table.xdebug-error tbody tr th {
      padding: 13px !important;
    }
    table.xdebug-error tbody tr td:nth-of-type(1) {
      width: 5% !important;
    }
    table.xdebug-error tbody tr th[bgcolor='#f57900'] {
      font-weight: normal;
      background: steelblue;
      color: white;
    }
    table.xdebug-error tbody tr th[bgcolor='#f57900'] span {
      display: none;
    }
    table.xdebug-error tbody tr font[color='#00bb00'] {
      color: #005e00;
    }
    table.xdebug-error tbody tr td small {
      display: none;
    }
    table.xdebug-error tbody tr td i {
      padding-left: 12px;
    }
    table.xdebug-error:hover {
      transform: none;
      opacity: 1;
    }
    

    缺点:

    • 根据您的其他 css defs,您可能需要稍微调整一下,直到它看起来像承诺的那样。
    • 它不如 Laravel/Symfony 错误那么漂亮

    优点:

    • 尽管出现错误,您仍可以看到实际页面。 (消息将变暗并在右侧推送,出现在鼠标悬停时。)

    • 只不过是 CSS

    • 您甚至可以通过CSS Live Editor Plugin 或类似的方式将其添加到您的页面;因此,无需添加到您自己的代码中

    • 它不会破坏您的样式,不会将大量文本填充到发生错误的小容器中,等等 - 因为它是 position:fixed

    • 赏心悦目 - 你最终会抛出错误只是为了再次看到它:)

    【讨论】:

      【解决方案2】:

      // notice the line height, the padding(cellspacing), monospace font, font size, making readability better at least for me.
      //
      // A FILENAME : xdebug_stack_trace.css
      // 
      // This is how the xdebug_stack_trace.css is called from the index.php page
      // 
      // <style><?php require_once("./resources/css/xdebug_stack_trace.css");?></ style>
      // 
      // notice that on the line above there is a space between the slash
      // and the 'style', on the ending 'style' tag, otherwise the display
      // get all messed up when this page gets loaded.
      // 
      // make sure that when you copy the 'style' line from here to the
      // index page, that you remove the extra space at the ending 'style'
      // tag of the index page.
      // +---------+---------+---------+---------+---------+---------+---------+
      // orange/black td header line
      // +---------+---------+---------+---------+---------+---------+---------+
      .xdebug-error th
      {
          font-family:monospace;
          font-weight:normal;
          font-size:15px;
          padding: 6px 6px 6px 6px;
          border:1px solid black;
          background: #FFCC99;    // orange
          color:#000000;          // black 
      }
      // +---------+---------+---------+---------+---------+---------+---------+
      // black/white th header line
      // +---------+---------+---------+---------+---------+---------+---------+
      .xdebug-error > tr:first-child > th:first-child,
      .xdebug-error > tbody > tr:first-child > th:first-child
      {
          line-height:1.6em;
          padding: 10px 10px 10px 10px;
          border:1px solid #000000;
          background: #000000;          // black
          color:#FFFFFF;
      }
      // +---------+---------+---------+---------+---------+---------+---------+
      // green/black td content one or more lines
      // +---------+---------+---------+---------+---------+---------+---------+
      .xdebug-error td
      {
          font-size:14px;
          padding: 6px 6px 6px 6px;
          border:1px solid green;
          background: #D1FFE8;          // light green
      }
      // +---------+---------+---------+---------+---------+---------+---------+
      

      【讨论】:

      • 添加一些描述,以便于理解您所写的内容
      【解决方案3】:

      另一个选项是禁止 xdebug 重载 var_dump。 在 php.ini [XDebug] 部分添加 xdebug.overload_var_dump=0

      格式化输出由您决定;一种方法是将var_dump 包装在您自己的调试函数中,该函数会打印<pre> 标签。

      【讨论】:

        【解决方案4】:

        解决方案是 !important 标签,它会覆盖现有的样式值。使用xdebug时使用如下css代码避免眼癌:

        .xdebug-error {
            font-size: 12px !important;
            width: 95% !important;
            margin: 0 auto 10px auto !important;
            border-color: #666 !important;
            background: #ddd !important;
        }
        
        .xdebug-error th, .xdebug-error td {
            padding: 2px !important;
        }
        
        .xdebug-error th {
            background: #ccc !important;
        }
        
        .xdebug-error span {
            display: none !important;
        }
        
        .xdebug-error_description th {
            font-size: 1.2em !important;
            padding: 20px 4px 20px 100px !important;
            background: #ccc no-repeat left top !important;
        }
        
        .xdebug-error_callStack th {
            background: #666 !important;
            color: #ddd !important;
        }
        

        【讨论】:

        • 眼癌 :) 覆盖 css 是唯一的解决方案吗?不可靠但很容易。也许与 append_file (在 apache 中)结合可能是一个全局解决方案。谢谢。
        • 我应该把这个 CSS 代码放在哪里?问题中链接到的页面不再存在...
        • 您需要自定义样式,例如通过浏览器中的插件。例如,我使用 Tampermonkey 和一个自定义脚本,它添加了 css 规则。看这个gist中的小脚本
        • 我对“眼癌”嗤之以鼻。
        猜你喜欢
        • 2015-01-25
        • 2019-08-19
        • 2021-12-04
        • 2021-05-04
        • 1970-01-01
        • 2011-08-22
        • 2012-05-08
        相关资源
        最近更新 更多