filisko / tracy-redbean
Tracy 的 RedBeanPHP 查询日志面板
1.0
2016-08-27 00:42 UTC
Requires
- gabordemooij/redbean: dev-master
- jdorn/sql-formatter: ^1.2
This package is auto-updated.
Last update: 2024-09-10 04:21:30 UTC
README
结果
安装和配置
使用 composer 安装它
composer require filisko/tracy-redbean
为了让它工作,你必须启用 RedBean 的调试模式以记录你的查询。你可以简单地使用 RedBean 的 Facade debug() 方法。
如何使用
基本示例
要使用此日志记录器与任何应用程序,你可以基本上这样做
R::setup('mysql:host=hostname;dbname=db', 'username', 'password'); /* Possible log modes: ------------------- 0 Log and write to STDOUT classic style (default) 1 Log only, class style 2 Log and write to STDOUT fancy style 3 Log only, fancy style (it works nicely with this one) */ R::debug(true, 3); // ... your queries here ... // Get RedBean's Logger $logger = R::getLogger(); // Create new instance of the panel $panel = new \Filisko\Tracy\RedBeanBarPanel($logger); // Boot the panel (collect and show the panel) \Filisko\Tracy\RedBeanBarPanel::boot($panel);
中间件示例
如果你使用的是与 PSR-7 工作的某些框架,你可以这样使用日志记录器
// Get RedBean's Logger $logger = R::getLogger(); // Create new instance of the panel $panel = new \Filisko\Tracy\RedBeanBarPanel($logger); // Add to middleware $app->add(new \Filisko\Tracy\RedBeanBarPanelMiddleware($panel));
附加功能
如果你意识到 RedBean 在你的 SQL 查询末尾添加了一些像 '--keep-cache' 这样的东西用于内部缓存目的,并且你想从日志记录器中隐藏这部分,你可以简单地使用一个静态标志来禁用它
\Filisko\Tracy\RedBeanBarPanel::$showKeepCache = false; // That's all!
如果你想更改面板的小图标或标题,请使用提供的静态变量
\Filisko\Tracy\RedBeanBarPanel::$icon = 'src/path/icon.png'; \Filisko\Tracy\RedBeanBarPanel::$title = 'RedBean query logger';
你可以查看 RedBean 的网站 调试页面 以更好地理解示例。