webxid / debug-helpers
v1.0.0
2022-04-06 10:23 UTC
Requires
- php: >=7.1
This package is auto-updated.
Last update: 2024-09-06 16:07:05 UTC
README
该库包含调试工具。它不依赖于其他库或框架,因此可以在任何项目中使用。
对我很有帮助。希望它对其他人也有帮助。
安装
运行 composer require webxid/debug-helpers
如何使用
简单数据转储
use function WebXID\DebugHelpers\_dump; use function WebXID\DebugHelpers\__dump; _dump($data); // To print data dump into a browser __dump($data); // To print data dump into a command line
转储回溯
use function WebXID\DebugHelpers\_backtrace; _backtrace(); // print a Back trace from a script start file to the currecn place
获取执行时间
use function WebXID\DebugHelpers\_trackTime; _trackTime('track_magic_time'); // start track of `track_magic_time` // Do a magic echo _trackTime('track_magic_time'); // print a `track_magic_time` execution time echo _trackTime(true); // print the all registered time track keys data
缓存变量数据
use function WebXID\DebugHelpers\_cachedLog; $var = 1; _cachedLog('$var', $var); $var = 2; _cachedLog('$var', $var); $var = 3; _cachedLog('$var', $var); // print cached data of the key `$var` print_r(_cachedLog('$var')); /** * will prints the array * [ * '$var' => [ * 1, * 2, * 3, * ], * ] */ print_r(_cachedLog()); // prints all cached data
将数据转储到日志文件
要转储数据到日志文件,请使用以下函数:
use WebXID\DebugHelpers\Environment; use function WebXID\DebugHelpers\_log; use function WebXID\DebugHelpers\_logWithClean; use function WebXID\DebugHelpers\_logAndDie; use function WebXID\DebugHelpers\_logWithCleanAndDie; Environment::setRootDir(__DIR__); _log($data); // Adds Dump of the $data var to the end of log file and continue a script procssing _logWithClean($data); // Cleaned up the log file, Dumps the $data var and continue a script procssing _logAndDie($data); // Adds Dump of the $data var to the end of log file and break a script processing _logWithCleanAndDie($data); // Cleaned up the log file, Adds Dump of the $data var to the end of log file and break a script processing
日志文件路径:Environment::getRootDir() . '/logs/webxid.log'。
!!! 注意 !!!
目录
logs必须对脚本可读和可写。否则,您将收到权限错误。