-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7816ede
commit d5c541d
Showing
8 changed files
with
65 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -632,7 +632,7 @@ state the exclusion of warranty; and each file should have at least | |
the "copyright" line and a pointer to where the full notice is found. | ||
|
||
<one line to give the program's name and a brief idea of what it does.> | ||
Copyright (C) 2018-2058 Nguyen An Hung <[email protected]> - https://nguyenanhung.com | ||
Copyright (C) 2018 - 2068 Nguyen An Hung <[email protected]> - https://nguyenanhung.com | ||
|
||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
|
@@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail. | |
If the program does terminal interaction, make it output a short | ||
notice like this when it starts in an interactive mode: | ||
|
||
nguyenanhung/my-debug Copyright (C) 2018-2058 Nguyen An Hung <[email protected]> - https://nguyenanhung.com | ||
nguyenanhung/my-debug Copyright (C) 2018 - 2068 Nguyen An Hung <[email protected]> - https://nguyenanhung.com | ||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. | ||
This is free software, and you are welcome to redistribute it | ||
under certain conditions; type `show c' for details. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,23 +39,23 @@ class Logger implements Project | |
/** @var bool Cấu hình trạng thái Debug, TRUE nếu cấu hình Debug được bật */ | ||
private $DEBUG = false; | ||
|
||
/** @var null|string Cấu hình Level lưu Log theo tiêu chuẩn RFC 5424 */ | ||
private $globalLoggerLevel = null; | ||
/** @var string|null Cấu hình Level lưu Log theo tiêu chuẩn RFC 5424 */ | ||
private $globalLoggerLevel; | ||
|
||
/** @var null|string Đường dẫn thư mục lưu trữ Log, VD: /your/to/path */ | ||
/** @var string|null Đường dẫn thư mục lưu trữ Log, VD: /your/to/path */ | ||
private $loggerPath = 'logs'; | ||
|
||
/** @var null|string Tương tự với $loggerPath, mặc định dùng để lưu tên class phát sinh log */ | ||
private $loggerSubPath = null; | ||
/** @var string|null Tương tự với $loggerPath, mặc định dùng để lưu tên class phát sinh log */ | ||
private $loggerSubPath; | ||
|
||
/** @var null|string Filename lưu log, khuyến nghị theo chuẩn Log-Y-m-d.log, VD: Log-2018-10-17.log */ | ||
private $loggerFilename = null; | ||
/** @var string|null Filename lưu log, khuyến nghị theo chuẩn Log-Y-m-d.log, VD: Log-2018-10-17.log */ | ||
private $loggerFilename; | ||
|
||
/** @var null|string Logger Date Format, VD: Y-m-d H:i:s u */ | ||
private $loggerDateFormat = null; | ||
/** @var string|null Logger Date Format, VD: Y-m-d H:i:s u */ | ||
private $loggerDateFormat; | ||
|
||
/** @var null|string Logger Line Format, VD: "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n" */ | ||
private $loggerLineFormat = null; | ||
/** @var string|null Logger Line Format, VD: "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n" */ | ||
private $loggerLineFormat; | ||
|
||
/** | ||
* Logger constructor. | ||
|
@@ -75,7 +75,7 @@ public function __construct() | |
* @copyright: 713uk13m <[email protected]> | ||
* @time : 08/17/2021 59:07 | ||
*/ | ||
public function getDebugStatus() | ||
public function getDebugStatus(): bool | ||
{ | ||
return $this->DEBUG; | ||
} | ||
|
@@ -90,7 +90,7 @@ public function getDebugStatus() | |
* @copyright: 713uk13m <[email protected]> | ||
* @time : 08/17/2021 59:17 | ||
*/ | ||
public function setDebugStatus($debug = false) | ||
public function setDebugStatus(bool $debug = false): Logger | ||
{ | ||
$this->DEBUG = $debug; | ||
|
||
|
@@ -123,7 +123,7 @@ public function getGlobalLoggerLevel() | |
* @see https://github.com/Seldaek/monolog/blob/master/doc/01-usage.md#log-levels | ||
* @see https://tools.ietf.org/html/rfc5424 | ||
*/ | ||
public function setGlobalLoggerLevel($globalLoggerLevel = null) | ||
public function setGlobalLoggerLevel(string $globalLoggerLevel = null): Logger | ||
{ | ||
if (!empty($globalLoggerLevel) && is_string($globalLoggerLevel)) { | ||
$this->globalLoggerLevel = strtolower($globalLoggerLevel); | ||
|
@@ -168,7 +168,7 @@ public function getLoggerSubPath() | |
* @copyright: 713uk13m <[email protected]> | ||
* @time : 08/17/2021 01:36 | ||
*/ | ||
public function setLoggerPath($loggerPath = '') | ||
public function setLoggerPath(string $loggerPath = ''): Logger | ||
{ | ||
if (!empty($loggerPath)) { | ||
$this->loggerPath = trim($loggerPath); | ||
|
@@ -187,7 +187,7 @@ public function setLoggerPath($loggerPath = '') | |
* @copyright: 713uk13m <[email protected]> | ||
* @time : 08/17/2021 02:19 | ||
*/ | ||
public function setLoggerSubPath($loggerSubPath = '') | ||
public function setLoggerSubPath(string $loggerSubPath = ''): Logger | ||
{ | ||
if (!empty($loggerSubPath)) { | ||
$this->loggerSubPath = trim($loggerSubPath); | ||
|
@@ -219,7 +219,7 @@ public function getLoggerFilename() | |
* @copyright: 713uk13m <[email protected]> | ||
* @time : 08/17/2021 03:20 | ||
*/ | ||
public function setLoggerFilename($loggerFilename = '') | ||
public function setLoggerFilename(string $loggerFilename = ''): Logger | ||
{ | ||
if (!empty($loggerFilename)) { | ||
$this->loggerFilename = trim($loggerFilename); | ||
|
@@ -246,7 +246,7 @@ public function getLoggerDateFormat() | |
/** | ||
* Function setLoggerDateFormat - Hàm quy định Date Format cho file Log | ||
* | ||
* @param null $loggerDateFormat Logger Date Format, VD: Y-m-d H:i:s u | ||
* @param string|null $loggerDateFormat Logger Date Format, VD: Y-m-d H:i:s u | ||
* | ||
* @return $this | ||
* @author : 713uk13m <[email protected]> | ||
|
@@ -256,7 +256,7 @@ public function getLoggerDateFormat() | |
* @see https://github.com/Seldaek/monolog/blob/master/doc/01-usage.md#customizing-the-log-format | ||
* @see https://github.com/Seldaek/monolog/blob/master/src/Monolog/Formatter/LineFormatter.php | ||
*/ | ||
public function setLoggerDateFormat($loggerDateFormat = null) | ||
public function setLoggerDateFormat(string $loggerDateFormat = null): Logger | ||
{ | ||
if (!empty($loggerDateFormat) && is_string($loggerDateFormat)) { | ||
$this->loggerDateFormat = $loggerDateFormat; | ||
|
@@ -293,7 +293,7 @@ public function getLoggerLineFormat() | |
* @see https://github.com/Seldaek/monolog/blob/master/doc/01-usage.md#customizing-the-log-format | ||
* @see https://github.com/Seldaek/monolog/blob/master/src/Monolog/Formatter/LineFormatter.php | ||
*/ | ||
public function setLoggerLineFormat($loggerLineFormat = null) | ||
public function setLoggerLineFormat($loggerLineFormat = null): Logger | ||
{ | ||
if (!empty($loggerLineFormat) && is_string($loggerLineFormat)) { | ||
$this->loggerLineFormat = $loggerLineFormat; | ||
|
@@ -320,11 +320,11 @@ public function setLoggerLineFormat($loggerLineFormat = null) | |
* | ||
* @example log('info', 'test', 'Log Test', []) | ||
*/ | ||
public function log($level = '', $name = 'log', $msg = 'My Message', $context = array()) | ||
public function log(string $level = '', string $name = 'log', string $msg = 'My Message', array $context = array()) | ||
{ | ||
$level = strtolower(trim($level)); | ||
if ($this->DEBUG == true) { | ||
if (!class_exists('\Monolog\Logger')) { | ||
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); | ||
|
@@ -345,7 +345,7 @@ public function log($level = '', $name = 'log', $msg = 'My Message', $context = | |
// Là 1 string | ||
is_string($this->globalLoggerLevel) && | ||
// Và thuộc list Level được quy định | ||
in_array($this->globalLoggerLevel, $listLevel) | ||
in_array($this->globalLoggerLevel, $listLevel, true) | ||
) { | ||
// If valid globalLoggerLevel -> use globalLoggerLevel | ||
$useLevel = strtolower($this->globalLoggerLevel); | ||
|
@@ -394,9 +394,9 @@ public function log($level = '', $name = 'log', $msg = 'My Message', $context = | |
} | ||
if (is_array($context)) { | ||
return $logger->$level($msg, $context); | ||
} else { | ||
return $logger->$level($msg . json_encode($context)); | ||
} | ||
|
||
return $logger->$level($msg . json_encode($context)); | ||
} catch (Exception $e) { | ||
if (function_exists('log_message')) { | ||
log_message('error', 'Error Message: ' . $e->getMessage()); | ||
|
@@ -423,7 +423,7 @@ public function log($level = '', $name = 'log', $msg = 'My Message', $context = | |
* @copyright: 713uk13m <[email protected]> | ||
* @time : 08/17/2021 07:35 | ||
*/ | ||
public function debug($name = 'log', $msg = 'My Message', $context = array()) | ||
public function debug(string $name = 'log', string $msg = 'My Message', array $context = array()) | ||
{ | ||
return $this->log('debug', $name, $msg, $context); | ||
} | ||
|
@@ -441,7 +441,7 @@ public function debug($name = 'log', $msg = 'My Message', $context = array()) | |
* @copyright: 713uk13m <[email protected]> | ||
* @time : 08/17/2021 07:35 | ||
*/ | ||
public function info($name = 'log', $msg = 'My Message', $context = array()) | ||
public function info(string $name = 'log', string $msg = 'My Message', array $context = array()) | ||
{ | ||
return $this->log('info', $name, $msg, $context); | ||
} | ||
|
@@ -459,7 +459,7 @@ public function info($name = 'log', $msg = 'My Message', $context = array()) | |
* @copyright: 713uk13m <[email protected]> | ||
* @time : 08/17/2021 07:35 | ||
*/ | ||
public function notice($name = 'log', $msg = 'My Message', $context = array()) | ||
public function notice(string $name = 'log', string $msg = 'My Message', array $context = array()) | ||
{ | ||
return $this->log('notice', $name, $msg, $context); | ||
} | ||
|
@@ -477,7 +477,7 @@ public function notice($name = 'log', $msg = 'My Message', $context = array()) | |
* @copyright: 713uk13m <[email protected]> | ||
* @time : 08/17/2021 07:35 | ||
*/ | ||
public function warning($name = 'log', $msg = 'My Message', $context = array()) | ||
public function warning(string $name = 'log', string $msg = 'My Message', array $context = array()) | ||
{ | ||
return $this->log('warning', $name, $msg, $context); | ||
} | ||
|
@@ -495,7 +495,7 @@ public function warning($name = 'log', $msg = 'My Message', $context = array()) | |
* @copyright: 713uk13m <[email protected]> | ||
* @time : 08/17/2021 07:35 | ||
*/ | ||
public function error($name = 'log', $msg = 'My Message', $context = array()) | ||
public function error(string $name = 'log', string $msg = 'My Message', array $context = array()) | ||
{ | ||
return $this->log('error', $name, $msg, $context); | ||
} | ||
|
@@ -513,7 +513,7 @@ public function error($name = 'log', $msg = 'My Message', $context = array()) | |
* @copyright: 713uk13m <[email protected]> | ||
* @time : 08/17/2021 07:35 | ||
*/ | ||
public function critical($name = 'log', $msg = 'My Message', $context = array()) | ||
public function critical(string $name = 'log', string $msg = 'My Message', array $context = array()) | ||
{ | ||
return $this->log('critical', $name, $msg, $context); | ||
} | ||
|
@@ -531,7 +531,7 @@ public function critical($name = 'log', $msg = 'My Message', $context = array()) | |
* @copyright: 713uk13m <[email protected]> | ||
* @time : 08/17/2021 07:35 | ||
*/ | ||
public function alert($name = 'log', $msg = 'My Message', $context = array()) | ||
public function alert(string $name = 'log', string $msg = 'My Message', array $context = array()) | ||
{ | ||
return $this->log('alert', $name, $msg, $context); | ||
} | ||
|
@@ -549,7 +549,7 @@ public function alert($name = 'log', $msg = 'My Message', $context = array()) | |
* @copyright: 713uk13m <[email protected]> | ||
* @time : 08/17/2021 07:35 | ||
*/ | ||
public function emergency($name = 'log', $msg = 'My Message', $context = array()) | ||
public function emergency(string $name = 'log', string $msg = 'My Message', array $context = array()) | ||
{ | ||
return $this->log('emergency', $name, $msg, $context); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
namespace nguyenanhung\MyDebug\Manager; | ||
|
||
use Exception; | ||
use Iterator; | ||
use SplFileInfo; | ||
use DateTime; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
|
@@ -31,7 +32,7 @@ | |
*/ | ||
class File extends Filesystem | ||
{ | ||
const VERSION = '1.0.0'; | ||
const VERSION = '3.0.1'; | ||
|
||
/** @var null|array Mảng dữ liệu chứa các thuộc tính cần quét */ | ||
private $scanInclude = ['*.log', '*.txt']; | ||
|
@@ -57,7 +58,7 @@ public function __construct() | |
* @time : 9/27/18 18:32 | ||
* | ||
*/ | ||
public function getVersion() | ||
public function getVersion(): string | ||
{ | ||
return self::VERSION; | ||
} | ||
|
@@ -66,8 +67,8 @@ public function getVersion() | |
* Hàm quét thư mục và list ra danh sách các file con | ||
* | ||
* @param string $path Đường dẫn thư mục cần quét, VD: /your/to/path | ||
* @param null|array $include Mảng dữ liệu chứa các thuộc tính cần quét | ||
* @param null|array $exclude Mảng dữ liệu chứa các thuộc tính bỏ qua không quét | ||
* @param array|null $include Mảng dữ liệu chứa các thuộc tính cần quét | ||
* @param array|null $exclude Mảng dữ liệu chứa các thuộc tính bỏ qua không quét | ||
* | ||
* @return \Iterator | ||
* @see https://github.com/theseer/DirectoryScanner/blob/master/samples/sample.php | ||
|
@@ -76,7 +77,7 @@ public function getVersion() | |
* @time : 10/17/18 10:19 | ||
* | ||
*/ | ||
public function directoryScanner($path = '', $include = NULL, $exclude = NULL) | ||
public function directoryScanner(string $path = '', array $include = null, array $exclude = null): Iterator | ||
{ | ||
$scanner = new DirectoryScanner(); | ||
if (is_array($include) && !empty($include)) { | ||
|
@@ -102,7 +103,7 @@ public function directoryScanner($path = '', $include = NULL, $exclude = NULL) | |
* @time : 10/17/18 10:23 | ||
* | ||
*/ | ||
public function setInclude($include = array()) | ||
public function setInclude(array $include = array()) | ||
{ | ||
$this->scanInclude = $include; | ||
} | ||
|
@@ -116,7 +117,7 @@ public function setInclude($include = array()) | |
* @time : 10/17/18 10:23 | ||
* | ||
*/ | ||
public function setExclude($exclude = array()) | ||
public function setExclude(array $exclude = array()) | ||
{ | ||
$this->scanExclude = $exclude; | ||
} | ||
|
@@ -132,7 +133,7 @@ public function setExclude($exclude = array()) | |
* @copyright: 713uk13m <[email protected]> | ||
* @time : 07/30/2020 59:36 | ||
*/ | ||
public function cleanLog($path = '', $dayToDelete = 3) | ||
public function cleanLog(string $path = '', int $dayToDelete = 3) | ||
{ | ||
try { | ||
$getDir = $this->directoryScanner($path, $this->scanInclude, $this->scanExclude); | ||
|
@@ -157,14 +158,13 @@ public function cleanLog($path = '', $dayToDelete = 3) | |
} | ||
|
||
return $result; | ||
} | ||
catch (Exception $e) { | ||
} catch (Exception $e) { | ||
if (function_exists('log_message')) { | ||
log_message('error', 'Error Message: ' . $e->getMessage()); | ||
log_message('error', 'Error Trace As String: ' . $e->getTraceAsString()); | ||
} | ||
|
||
return FALSE; | ||
return false; | ||
} | ||
} | ||
|
||
|
@@ -178,7 +178,7 @@ public function cleanLog($path = '', $dayToDelete = 3) | |
* @copyright: 713uk13m <[email protected]> | ||
* @time : 07/30/2020 03:15 | ||
*/ | ||
public function scanAndCleanLog($listFolder = array(), $dayToDelete = 3) | ||
public function scanAndCleanLog(array $listFolder = array(), int $dayToDelete = 3) | ||
{ | ||
if (empty($listFolder)) { | ||
echo "Không có mảng dữ liệu cần quét"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,13 @@ | |
*/ | ||
interface Project | ||
{ | ||
const VERSION = '3.0.0'; | ||
const VERSION = '3.0.1'; | ||
|
||
/** | ||
* Hàm lấy thông tin phiên bản Packages | ||
* | ||
* @return string Phiên bản hiện tại của Packages, VD: 0.1.1 | ||
* @return string Phiên bản hiện tại của Packages, VD: 2.0.1 | ||
* | ||
* @author : 713uk13m <[email protected]> | ||
* @copyright: 713uk13m <[email protected]> | ||
* @time : 9/27/18 18:32 | ||
|
Oops, something went wrong.