jambagecom / fh-debug
PHP 调试器,sys_log 和 devLog 记录器
Requires
- typo3/cms-core: ^10.4 || ^11.5 || ^12.0 || ^13.0
Suggests
- jambagecom/tsparser: ^0.9
Replaces
- typo3-ter/fh-debug: v0.17.2
This package is auto-updated.
Last update: 2024-09-01 16:43:32 UTC
README
安装需求
您必须覆盖经典安装中的 TYPO3 核心文件 sysext/core/Resources/PHP/GlobalDebugFunctions.php
,或者Composer安装中的 vendor/typo3/cms-core/Resources/PHP/GlobalDebugFunctions.php
,使用文件 fh_debug/Patches/TYPO3/sysext/core/Resources/PHP/GlobalDebugFunctions.php
。或者,您可以在您的composer.json中使用"post-install-cmd"或"post-autoload-dump"和文件复制方法。请参阅 定义脚本。
这将使您重新获得 TYPO3 核心中的旧方法 debugBegin 和 debugEnd。这还包含在扩展管理器中激活 fh_debug 所需的 PHP 代码。只有通过此文件替换,fh_debug 才能正常工作。
它做什么
使用此扩展生成 TYPO3 和 TYPO3 扩展的 PHP 代码在前后端中的调试输出文件,如果它们包含 PHP 调试语句。如果想要调试生成的 SQL 查询或追踪在 sys_log 表中记录的 PHP 错误或在 TYPO3 函数 devLog 中写入的开发者跟踪,请考虑安装 debug_mysql_db。
调试输出写入 HTML 调试输出文件。所有配置都在扩展管理器中完成。您可以使用 CSS 文件 fhdebug.css
设计输出。如果您有大量的调试输出,那么您应该在 PHP 调试命令周围放置 debug (‘B’)
(以前是 debugBegin()
)和 debug (‘E’)
(以前是 debugEnd()
)PHP 命令,以便在文件中减少调试输出行数。这些命令将激活和禁用调试输出。
强制输出
自版本 0.8.3 以来:如果需要 debug (‘B’)
,但可能不是激活状态,则可以使用第三个参数 (group) ‘F’
强制输出。这是一个特殊情况,无论 debug (‘B’)
是否设置为必须,都会产生输出。
示例
debug ('B'); $a = 'myString'; debug ($a, '$a at position 1'); debug ('E');
屏幕上不会显示任何调试输出。否则,您必须在安装工具中禁用调试输出。
$a = 'myString2'; debug ($a, '$a at position 1', 'F');
调试输出将始终显示。
新闻
自版本 0.15.0 以来,如果全局错误对象不存在,则会自动初始化。这允许在 Middleware 被分发之前,几乎在任何地方在 TYPO3 后端中插入调试调用。
配置
请输入任何无效的 IP 地址
[SYS][devIPmask] = 1.1.1.1
fh_debug 的扩展管理器配置将添加到安装工具的 IP 地址。 IPADDRESS = 34.22.11.12
。您的当前 IP 地址显示在 fh_debug 的扩展管理器视图中的 IPADDRESS
字段下方。如果您的提供商已激活 ip 版本 6,则必须以 IPv6 格式输入。
示例
如果您想调试此客户端的操作,请输入您的当前 IP 地址 11.12.13.14。
LocalConfiguration.php
使用 fh_debug 错误处理器以获取所有异常的调试消息。将这些行添加到 typo3conf 下的 LocalConfiguration.php
文件中。
'SYS' => array( 'displayErrors' => '2', 'errorHandler' => 'JambageCom\\FhDebug\\Hooks\\ErrorHandler', ),
您可以使用 TYPO3 错误消息 Oops, an error occurred! 显示更多调试信息和回溯。默认情况下:OOPS_AN_ERROR_OCCURRED = 1
。这也会向调试文件添加详细的调试输出。
要获取“Oops,发生错误!”的调试输出,您必须在安装工具或LocalConfiguration.php
中进行此配置。
- [SYS][productionExceptionHandler] =
- JambageCom\FhDebug\Hooks\CoreProductionExceptionHandler
在卸载fh_debug之前,请删除此设置。否则,您将获得此PHP错误条目
PHP 致命错误:未捕获的错误:类‘JambageCom\FhDebug\Hooks\CoreProductionExceptionHandler’在/var/www/html/typo3_src-9.5.8/typo3/sysext/core/Classes/Utility/GeneralUtility.php的第3667行未找到
默认设置是
[SYS][productionExceptionHandler] = TYPO3\CMS\Core\Error\ProductionExceptionHandler
示例
if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('fh_debug')) { require_once(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('fh_debug') . 'Classes/Utility/DebugFunctions.php'); // use t3lib_extMgm::extPath in TYPO3 4.5 // some configuration: \JambageCom\Fhdebug\Utility\DebugFunctions::setErrorLogFile(''); // this is necessary if you use the error_log file // if you use the debug HTML file: \JambageCom\Fhdebug\Utility\DebugFunctions::setDebugFile('fileadmin/debug.html'); \JambageCom\Fhdebug\Utility\DebugFunctions::setDebugBegin(FALSE); \JambageCom\Fhdebug\Utility\DebugFunctions::setRecursiveDepth('12'); \JambageCom\Fhdebug\Utility\DebugFunctions::setTraceDepth('12'); \JambageCom\Fhdebug\Utility\DebugFunctions::setAppendDepth('0'); \JambageCom\Fhdebug\Utility\DebugFunctions::setTypo3Mode('ALL'); \JambageCom\Fhdebug\Utility\DebugFunctions::setActive(TRUE); \JambageCom\Fhdebug\Utility\DebugFunctions::initFile(); } \JambageCom\Fhdebug\Utility\DebugFunctions::debug ($_EXTCONF, '$_EXTCONF');
如果您使用的是ext_localconf.php
或首先执行的一些TYPO3核心文件,那么fh_debug扩展尚未初始化。因此,您必须使用完整命名空间类来初始化并调用fh_debug的类。
类‘JambageCom\Fhdebug\Utility\DebugFunctions’在/var/www/html/typo3_src/typo3/sysext/core/Resources/PHP/GlobalDebugFunctions.php的第15行未找到
这意味着您的调试输出应在TYPO3初始化fh_debug扩展之前生成。您必须通过以下命令自行初始化
示例
require_once(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('fh_debug') . 'Classes/Utility/DebugFunctions.php'); \JambageCom\Fhdebug\Utility\DebugFunctions::init(); \JambageCom\Fhdebug\Utility\DebugFunctions::setErrorLogFile(''); \JambageCom\Fhdebug\Utility\DebugFunctions::setDebugFile('fileadmin/debug.html'); debug ($tmp, 'variable before fh_debug has been started yet.');
debug 开始和结束
有2个控制命令可用于开始和结束调试输出的生成:debug ('B')
和 debug ('E')
,在TYPO3 9.5之前为debugBegin()
和 debugEnd()
。
debugBegin 和 debugEnd 函数的替代方案
由于从TYPO3 9开始需要全局函数已被移除,自fh_debug 0.8.0版以来引入了一个解决方案。
示例
debug ('B'); // begin debugging debug ($myVariable, 'my variable'); debug ('E'); // end debugging
版本0.8.0之前的示例
debugBegin(); debug ($myVariable, 'my variabled'); debugEnd();
错误
如果fh_debug不起作用,那么可能的情况是fh_debug尚未激活。您可以使用PHP错误日志作为替代。
PHP error_log 示例
error_log('mymethod Position 2 $variableName: ' . print_r($variableName, true) . PHP_EOL, 3, '/var/www/html/fileadmin/phpDebugErrorLog.txt');
在上面的方法 error_log 的最后一个参数中使用您自己的路径
故障排除
如果您在浏览器URL中看不到任何内容 https://example.com/fileadmin/debug.html,请确保文件系统上确实存在此文件 debug.html。如果不是,则在文件夹 fileadmin
中创建一个空文件 debug.html
并将Apache的写入权限赋予它。
检查扩展管理器中的配置。客户端浏览器的IP地址用星号*放入。然后,每个客户端IP地址都会生成调试输出。
改进
请在添加控制函数以进行调试 增强调试方法的TYPO3核心错误跟踪器中直接创建条目。
全局函数只能在TYPO3核心中实现。
待办事项
编写一个覆盖TYPO3核心文件的TYPO3补丁扩展程序。