Glowie调试栏插件

v1.2.0 2024-04-20 01:12 UTC

This package is auto-updated.

Last update: 2024-09-10 22:21:30 UTC


README

Debugger是Glowie框架的一个插件,为开发者提供了一个功能强大的调试栏。

Debugger

功能

  • 美观简单的调试栏,无需配置
  • 将消息、警告、错误和变量打印并过滤到控制台窗口
  • 捕获并打印异常和堆栈跟踪到控制台
  • 测量长时间操作到时间线,提高您的应用程序性能
  • 检查请求和响应变量和头信息
  • 检查会话和Cookie数据
  • 记录SQL查询、绑定和查询持续时间
  • 检查渲染视图、布局及其所有参数
  • 检查应用程序信息、路由、内存使用、软件版本、请求时间等
  • 自动切换浅色和深色主题

安装

使用Composer在您的Glowie项目中安装

composer require glowieframework/debugger

然后,将Debugger类添加到app/config/Config.php文件中的plugins数组

'plugins' => [
    // ... other plugins here
    \Glowie\Plugins\Debugger\Debugger::class,
],

在您的应用程序主布局或所需的视图内,将Skeltch指令添加到页面底部,在</body>标签之前

<body>
    <!-- your page content here -->
    { debugger }
</body>

如果您不使用Skeltch模板引擎,您也可以使用默认的PHP调用

<body>
    <!-- your page content here -->
    <?php \Glowie\Plugins\Debugger\Debugger::render(); ?>
</body>

调试模式

调试栏不应在生产模式下使用。要正常工作,您应用程序的.env文件中的APP_DEBUG配置必须设置为true不要忘记在生产环境中禁用此设置。

APP_DEBUG=true

运行时启用或禁用调试栏

要启用或禁用调试栏的渲染,使用以下命令:

use Glowie\Plugins\Debugger\Debugger;

Debugger::enable();

Debugger::disable();

注意:如果您的应用程序环境中禁用了调试模式,则enable()方法将不会执行任何操作。

使用方法

控制台窗口

要向控制台窗口发送消息,请使用以下任何一种方法:

use Glowie\Plugins\Debugger\Debugger;

Debugger::log('Hello world!'); // Prints an info message
// or
Debugger::info('Hello world!');

Debugger::error('Something went wrong...'); // Prints an error message

Debugger::warning('Remember to check the docs.'); // Prints a warning message

Debugger::dump($myVar); // Dumps a variable to the console

异常窗口

要捕获异常并将它们打印到异常标签页,请使用以下方法:

use Glowie\Plugins\Debugger\Debugger;

try {
    throw new Exception('Whoops!');
} catch (Exception $e) {
    Debugger::exception($e);
}

时间线窗口

您可以使用以下方法来测量操作:

use Glowie\Plugins\Debugger\Debugger;

Debugger::startTimer('test', 'My timer description');
// your long operation
Debugger::stopTimer('test');

// or
Debugger::measure('Test', function(){
    // your long operation
});

清除信息

要清除调试栏数据,请使用以下方法:

use Glowie\Plugins\Debugger\Debugger;

Debugger::clear(); // Clears the console

Debugger::clearExceptions(); // Clears the exceptions

Debugger::clearTimers(); // Clears the timers

Debugger::clearQueries(); // Clears the queries

鸣谢

Debugger和Glowie目前由Gabriel Silva开发。