mortimer333 / orator
dev-master
2022-10-04 18:03 UTC
Requires
- php: >=8.1
- ext-mbstring: *
This package is auto-updated.
Last update: 2024-09-04 22:21:56 UTC
README
PHP日志记录器
概述
一个有用的库,用于格式化日志(不再有混乱的 vardump)。没有CSS,只有缩进和 JSON_PRETTY_PRINT
(最佳使用场景是在文件内部,但 <pre>
也可以满足需求)。
如何使用
use Orator\Log; Log::log('Log A'); // Log A Log::increaseIndent(); Log::log('Log B'); // →→Log A Log::decreaseIndent(); Log::log(['asd' => 'asd']); /* Output: { "asd": "asd" } */ $log = "First line Second Line"; Log::log($log); // First line\nSecond Line // Set $addClass and $addFunction to true class LogClass { public static function test() { Log::log('Test'); } } LogClass::test(); // Tetraquark\LogClass | test * Test
选项
当前几乎没有选项可以更改日志在运行过程中的行为,因此任何更改都必须直接在 Log
文件内部进行。
详细程度
您可以通过将 Log
方法的第二个参数传递来定义日志输出的重要性
Log::log("log", 2);
如果 $maxVerbose
大于或等于日志中的 $verbose
,则将输出。
跟踪级别
当启用 $addClass
和 $addFunction
时,您可以决定在调试跟踪中要后退多少
class LogClass { public static function test(int $trace = 0) { Log::log('Test', null, $trace); } public static function testNested() { self::test(1); } } LogClass::test(); // Tetraquark\LogClass | test * Test LogClass::testNested(); // Tetraquark\LogClass | testNested * Test
运行时间
通过调用 timerStart
和 timerEnd
,您将获得这两个调用之间的时间差,单位为千分之一秒
Log::timerStart(); for ($i=0; $i < 10**6; $i++) { // code... } Log::timerEnd(); // Duration: 0.024s
停止替换新行
如果您想在日志中显示新行,请在 Log
方法中将 $replaceNewLine
设置为 false
Log::log("Line 1\nLine 2", replaceNewLine: false); /* Output: Line 1 Line 2 */