1 thư viện nhỏ hỗ trợ việc ghi log, benchmark ứng dụng PHP. Được customize lại cho phù hợp mục đích sử dụng
- V1.x support all PHP version
>=5.6
- V2.x support all PHP version
>=5.6
- V3.x support all PHP version
>=7.0
- V4.x support all PHP version
>=8.1
Ngoài ra, gói cũng hỗ trợ logging lên service ngoài như Sentry, khi đó cần cài thêm gói sentry/sdk
như dưới đây
- sentry/sdk
^3.0 || ^2.0
Tham khảo hướng dẫn triển khai tại đây và trong thư mục test/
<?php
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/functions.php';
use nguyenanhung\MyDebug\Logger;
// Test Content
$logPath = __DIR__.'/tmp';
$logSubPath = 'tests-debug-2';
$logFilename = 'Log-' . date('Y-m-d') . '.log';
$name = 'Test';
$msg = 'Test Log lan 2';
$context = [
'name' => 'Nguyen An Hung',
'email' => '[email protected]'
];
// Call
$debug = new Logger();
$debug->setDebugStatus(TRUE);
$debug->setGlobalLoggerLevel('info');
$debug->setLoggerPath($logPath);
$debug->setLoggerSubPath($logSubPath);
$debug->setLoggerFilename($logFilename);
$debug->__construct();
echo "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
echo "\n getVersion: " . $debug->getVersion() . "\n";
echo "\n setDebugStatus: " . $debug->getDebugStatus() . "\n";
echo "\n setLoggerPath: " . $debug->getLoggerPath() . "\n";
echo "\n setLoggerSubPath: " . $debug->getLoggerSubPath() . "\n";
echo "\n setLoggerFilename: " . $debug->getLoggerFilename() . "\n";
echo "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
d($debug->debug($name, $msg . ' - DEBUG', $context));
d($debug->info($name, $msg . ' - INFO', $context));
d($debug->notice($name, $msg . ' - NOTICE', $context));
d($debug->warning($name, $msg . ' - WARNING', $context));
d($debug->error($name, $msg . ' - ERROR', $context));
d($debug->critical($name, $msg . ' - CRITICAL', $context));
d($debug->alert($name, $msg . ' - ALERT', $context));
d($debug->emergency($name, $msg . ' - EMERGENCY', $context));
<?php
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/functions.php';
use nguyenanhung\MyDebug\Benchmark;
$benchmark = new Benchmark();
/***************************** SIMPLE BENCHMARKING BY CI *****************************/
$benchmark->mark('code_start');
$mathFunctions = array("abs", "acos", "asin", "atan", "floor", "exp", "sin", "tan", "pi", "is_finite", "is_nan", "sqrt");
$count = 9999;
for ($i = 0; $i < $count; $i++) {
foreach ($mathFunctions as $key => $function) {
$function($i);
echo ($key + 1) . " -> " . $function . "\n";
}
}
$benchmark->mark('code_end');
d($benchmark->elapsed_time('code_start', 'code_end'));
d($benchmark->memory_usage());
/***************************** SIMPLE BENCHMARKING BY CI *****************************/
<?php
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/functions.php';
use nguyenanhung\MyDebug\Manager\File;
$file = new File();
$file->setExclude(['*.zip']);
$file->setInclude(['*.log']);
d($file->getVersion());
d($file->cleanLog(__DIR__.'/tmp', 7));
<?php
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/functions.php';
use nguyenanhung\MyDebug\Utils;
$utils = new Utils();
$str = 'Nguyễn An Hưng';
d($utils->getVersion()); // show "2.0.5"
d($utils::slugify($str)); // show "nguyen-an-hung"
If any question & request, please contact following information
Name | Skype | ||
---|---|---|---|
Hung Nguyen | [email protected] | nguyenanhung5891 | @nguyenanhung |
From Vietnam with Love <3