nguyenanhung/my-debug

v4.0.8 2024-09-21 19:06 UTC

README

Latest Stable Version Total Downloads Daily Downloads Monthly Downloads License PHP Version Require

My Debug

一个轻量级的PHP日志和基准测试库。可根据需求进行定制。

版本

  • V1.x 支持所有PHP版本 >=5.6
  • V2.x 支持所有PHP版本 >=5.6
  • V3.x 支持所有PHP版本 >=7.0
  • V4.x 支持所有PHP版本 >=8.1

此外,此包还支持将日志记录到外部服务(如Sentry),此时需要安装额外的包 sentry/sdk,如下所示

  • sentry/sdk ^3.0 || ^2.0

用法

请参考以下部署指南和 test/ 目录中的内容

调试 & 日志

<?php
require_once __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/func.php';

use nguyenanhung\MyDebug\Logger;

// Test Content
$logPath = __DIR__ . '/../tmp';
$logPath = realpath($logPath);
$logSubPath = date('Y-m-d');
$logFilename = 'Log-' . date('Y-m-d') . '.log';
$name = 'Test';
$msg = 'Test Log lan 2';
$context = [
	'name' => 'Nguyen An Hung',
	'email' => 'dev@nguyenanhung.com',
	'website' => 'https://nguyenanhung.com',
];
// Call
$logger = new Logger();
$logger->setDebugStatus(true);
$logger->setGlobalLoggerLevel();
$logger->setLoggerPath($logPath);
$logger->setLoggerSubPath($logSubPath);
$logger->setLoggerFilename($logFilename);
$logger->__construct();
echo "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
echo "\n getVersion: " . $logger->getVersion() . "\n";
echo "\n setDebugStatus: " . $logger->getDebugStatus() . "\n";
echo "\n setLoggerPath: " . $logger->getLoggerPath() . "\n";
echo "\n setLoggerSubPath: " . $logger->getLoggerSubPath() . "\n";
echo "\n setLoggerFilename: " . $logger->getLoggerFilename() . "\n";
echo "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";

__show__($logger->debug($name, $msg . ' - DEBUG', $context));
__show__($logger->info($name, $msg . ' - INFO', $context));
__show__($logger->notice($name, $msg . ' - NOTICE', $context));
__show__($logger->warning($name, $msg . ' - WARNING', $context));
__show__($logger->error($name, $msg . ' - ERROR', $context));
__show__($logger->critical($name, $msg . ' - CRITICAL', $context));
__show__($logger->alert($name, $msg . ' - ALERT', $context));
__show__($logger->emergency($name, $msg . ' - EMERGENCY', $context));

基准测试

<?php
require_once __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/func.php';

use nguyenanhung\MyDebug\Benchmark;

$benchmark = new Benchmark();
$benchmark->mark('code_start');
$mathFunctions = ["abs", "acos", "asin", "atan", "floor"];
$count = 10;
for ($i = 0; $i < $count; $i++) {
	foreach ($mathFunctions as $key => $function) {
		$function($i);
		echo ($key + 1) . " -> " . $function . "\n";
	}
}
$benchmark->mark('code_end');

__show__($benchmark->elapsed_time('code_start', 'code_end'));
__show__($benchmark->memory_usage());

文件管理

<?php
require_once __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/func.php';

use nguyenanhung\MyDebug\Manager\File;

$file = new File();
$file->setExclude(array('*.zip'));
$file->setInclude(array('*.log'));

$path = __DIR__ . '/../tmp';
$path = realpath($path);

__show__($file->directoryScanner($path));

工具

<?php
require_once __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/func.php';

use nguyenanhung\MyDebug\Utils;

$utils = new Utils();
$str = 'Nguyễn An Hưng';

__show__($utils->getVersion());
__show__($utils::slugify($str));

支持

如有任何疑问和建议,请联系以下信息

来自越南,充满爱 <3