Skip to content

Commit

Permalink
Merge pull request #56 from nguyenanhung/v4.x
Browse files Browse the repository at this point in the history
V4.x
  • Loading branch information
nguyenanhung authored Apr 1, 2024
2 parents e0bb01d + 2a4aaec commit 1e6711c
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 116 deletions.
7 changes: 7 additions & 0 deletions .ide.purpose.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
defined('BASE_DEV_IDE') or exit('No direct script access allowed');
if (!function_exists('log_message')) {
function log_message($name, $message): void
{
}
}
103 changes: 52 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,105 +30,106 @@ Tham khảo hướng dẫn triển khai tại đây và trong thư mục `test/`
```php
<?php
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/functions.php';
require __DIR__ . '/func.php';

use nguyenanhung\MyDebug\Logger;

// Test Content
$logPath = __DIR__.'/tmp';
$logSubPath = 'tests-debug-2';
$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' => '[email protected]'
$name = 'Test';
$msg = 'Test Log lan 2';
$context = [
'name' => 'Nguyen An Hung',
'email' => '[email protected]',
'website' => 'https://nguyenanhung.com',
];
// Call
$debug = new Logger();
$debug->setDebugStatus(TRUE);
$debug->setGlobalLoggerLevel('info');
$debug->setLoggerPath($logPath);
$debug->setLoggerSubPath($logSubPath);
$debug->setLoggerFilename($logFilename);
$debug->__construct();
$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: " . $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 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";

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));
__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));
```

### Benchmark

```php
<?php
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/functions.php';
require __DIR__ . '/func.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;
$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";
}
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 *****************************/
__show__($benchmark->elapsed_time('code_start', 'code_end'));
__show__($benchmark->memory_usage());
```

### Manage File

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

use nguyenanhung\MyDebug\Manager\File;

$file = new File();
$file->setExclude(['*.zip']);
$file->setInclude(['*.log']);
d($file->getVersion());
d($file->cleanLog(__DIR__.'/tmp', 7));
$file->setExclude(array('*.zip'));
$file->setInclude(array('*.log'));

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

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

### Utils

```php
<?php
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/functions.php';
require __DIR__ . '/func.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"
$str = 'Nguyễn An Hưng';

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

## Support
Expand All @@ -139,4 +140,4 @@ If any question & request, please contact following information
|-------------|----------------------|------------------|---------------|
| Hung Nguyen | [email protected] | nguyenanhung5891 | @nguyenanhung |

From Vietnam with Love <3
From Vietnam with Love <3
19 changes: 4 additions & 15 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,7 @@ public function log(string $level = '', string $name = 'log', string $msg = 'My
$level = mb_strtolower(trim($level));
if ($this->DEBUG === true) {
if (!class_exists(MonoLogger::class)) {
if (function_exists('log_message')) {
$errorMsg = 'Không tồn tại class Monolog';
log_message('error', $errorMsg);
}

Utils::log_message('error', 'Class Monolog not exists');
return false;
}
try {
Expand Down Expand Up @@ -388,20 +384,13 @@ public function log(string $level = '', string $name = 'log', string $msg = 'My
$msg = 'My Log Message is Empty';
}

if (is_array($context)) {
$contextData = $context;
} else {
$contextData = [$context];
}
$contextData = is_array($context) ? $context : [$context];
$logger->$level($msg, $contextData);

return true;
} catch (Exception $e) {
if (function_exists('log_message')) {
log_message('error', 'Error Message: ' . $e->getMessage());
log_message('error', 'Error TraceAsString: ' . $e->getTraceAsString());
}

Utils::log_message('error', 'Error Message: ' . $e->getMessage());
Utils::log_message('error', 'Error TraceAsString: ' . $e->getTraceAsString());
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
interface Project
{
const VERSION = '4.0.3';
const VERSION = '4.0.4';

/**
* Hàm lấy thông tin phiên bản Packages
Expand Down
24 changes: 24 additions & 0 deletions src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,28 @@ public static function slugify(string $str = ''): string
{
return (new SlugUrl())->slugify($str);
}

/**
* Function log_message - Call to function log_message if function exists
*
* @param string $name
* @param mixed $message
* @return void
*/
public static function log_message(string $name = '', mixed $message = ''): void
{
if (empty($name)) {
$name = 'error';
}
if (function_exists('log_message') && !empty($message)) {
if (!is_string($message)) {
$message = json_encode(
[
$message
]
);
}
log_message($name, $message);
}
}
}
8 changes: 0 additions & 8 deletions test/func.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
<?php
/**
* Project my-debug
* Created by PhpStorm
* User: 713uk13m <[email protected]>
* Copyright: 713uk13m <[email protected]>
* Date: 14/01/2023
* Time: 01:29
*/
if (!function_exists('__show__')) {
function __show__($s): void
{
Expand Down
12 changes: 1 addition & 11 deletions test/test_benchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,9 @@
require_once __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/func.php';

/**
* Project vn-telco-detect.
* Created by PhpStorm.
* User: 713uk13m <[email protected]>
* Date: 9/18/18
* Time: 17:30
*/

use nguyenanhung\MyDebug\Benchmark;

$benchmark = new Benchmark();
/***************************** SIMPLE BENCHMARKING BY CI *****************************/
$benchmark->mark('code_start');
$mathFunctions = ["abs", "acos", "asin", "atan", "floor"];
$count = 10;
Expand All @@ -25,7 +16,6 @@
}
$benchmark->mark('code_end');


__show__($benchmark->elapsed_time('code_start', 'code_end'));
__show__($benchmark->memory_usage());
/***************************** SIMPLE BENCHMARKING BY CI *****************************/

13 changes: 1 addition & 12 deletions test/test_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
require_once __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/func.php';

/**
* Project vn-telco-detect.
* Created by PhpStorm.
* User: 713uk13m <[email protected]>
* Date: 9/18/18
* Time: 17:30
*/

use nguyenanhung\MyDebug\Manager\File;

$file = new File();
Expand All @@ -19,7 +11,4 @@
$path = __DIR__ . '/../tmp';
$path = realpath($path);

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



__show__($file->directoryScanner($path));
9 changes: 0 additions & 9 deletions test/test_logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
require_once __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/func.php';

/**
* Project vn-telco-detect.
* Created by PhpStorm.
* User: 713uk13m <[email protected]>
* Date: 9/18/18
* Time: 17:30
*/

use nguyenanhung\MyDebug\Logger;

// Test Content
Expand Down Expand Up @@ -48,4 +40,3 @@
__show__($logger->critical($name, $msg . ' - CRITICAL', $context));
__show__($logger->alert($name, $msg . ' - ALERT', $context));
__show__($logger->emergency($name, $msg . ' - EMERGENCY', $context));

9 changes: 0 additions & 9 deletions test/test_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,10 @@
require_once __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/func.php';

/**
* Project vn-telco-detect.
* Created by PhpStorm.
* User: 713uk13m <[email protected]>
* Date: 9/18/18
* Time: 17:30
*/

use nguyenanhung\MyDebug\Utils;

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

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

0 comments on commit 1e6711c

Please sign in to comment.