From 1e1e62750085fccd0939161579da5ed367cefbb3 Mon Sep 17 00:00:00 2001 From: levani Date: Fri, 21 Sep 2018 15:30:16 +0400 Subject: [PATCH 1/3] Add comments for every function delete log folder --- CliColor.php | 4 ++++ CliLogger.php | 48 +++++++++++++++++++++++++++++++++++++++++++++--- logs/.gitignore | 2 -- 3 files changed, 49 insertions(+), 5 deletions(-) delete mode 100644 logs/.gitignore diff --git a/CliColor.php b/CliColor.php index 15e407f..3cd0a4d 100644 --- a/CliColor.php +++ b/CliColor.php @@ -10,6 +10,7 @@ class CliColor { + // Text color options for log text const F_BLACK = '0;30'; const F_DARK_GREY = '1;30'; const F_BLUE = '0;34'; @@ -37,6 +38,9 @@ class CliColor const B_LIGHT_GRAY = '47'; /** + * Get colored string + * + * Returns colored string with chosen configuration for log text * @param $string * @param null $foregroundColor * @param null $backgroundColor diff --git a/CliLogger.php b/CliLogger.php index 0085990..fcca5b8 100644 --- a/CliLogger.php +++ b/CliLogger.php @@ -11,22 +11,25 @@ class CliLogger { - + //log file creation types const FILE_CREATE_TYPE_BY_TIME = 1; - const FILE_CREATE_TYPE_BY_SIZE = 2; + //color option for log text public $enableColors = true; + //log file creation type property public $fileCreateType = self::FILE_CREATE_TYPE_BY_SIZE; + //Log file recreation units public $fileReCreateMinutes = 1; public $fileReCreateHours = 0; public $fileReCreateDays = 0; public $fileReCreateMonths = 0; public $fileReCreateYears = 0; - public $filReCreateSize = 900; + //Log file recreation size + public $filReCreateSize = 900; //size in bytes // Log file attributes public $logFilePath; @@ -54,11 +57,16 @@ public function __construct($config) /** + * Log message + * + * Log message with color parameters in log file + * * @param $message * @param string $fColor * @param null $bColor * @param string $type * @return string + * @throws \Exception */ public function log($message, $fColor = CliColor::F_WHITE, $bColor = null, $type = 'LOG') { @@ -67,9 +75,12 @@ public function log($message, $fColor = CliColor::F_WHITE, $bColor = null, $type /** + * Log error + * * @param $message * @param string $type * @return string + * @throws \Exception */ public function error($message, $type = 'ERROR') { @@ -78,9 +89,12 @@ public function error($message, $type = 'ERROR') /** + * Log info + * * @param $message * @param string $type * @return string + * @throws \Exception */ public function info($message, $type = 'INFO') { @@ -89,9 +103,12 @@ public function info($message, $type = 'INFO') /** + * Log success + * * @param $message * @param string $type * @return string + * @throws \Exception */ public function success($message, $type = 'SUCCESS') { @@ -100,6 +117,10 @@ public function success($message, $type = 'SUCCESS') /** + * Log write + * + * Write log message with given type and text color parameters in log file + * * @param $message * @param $fColor * @param null $bColor @@ -124,6 +145,10 @@ private function writeLog($message, $fColor, $bColor = null) /** + * Constructor configuration + * + * Returns configuration object for constructor + * * @param $object * @param $properties * @return mixed @@ -139,6 +164,10 @@ private function configure($object, $properties) /** + * Log file template + * + * Returns template for log file with chosen configuration + * * @param $expiredLogFile * @return bool|mixed|string */ @@ -175,6 +204,9 @@ private function processFileTemplate($expiredLogFile) /** + * Log text template + * + * Returns template for log text with chosen configuration * @param $message * @param string $type * @return string @@ -192,6 +224,12 @@ private function processLogTextTemplate($message, $type = 'LOG') /** + * File creation check + * + * Function checks if log file was created according FILE_CREATE_TYPE option + * + * Returns log file name or boolean(false) + * * @return bool|mixed */ private function checkFileCreation() @@ -224,6 +262,10 @@ private function checkFileCreation() /** + * Get latest log + * + * Return latest log file from log directory + * * @return bool|mixed */ private function getLatestLogFile() diff --git a/logs/.gitignore b/logs/.gitignore deleted file mode 100644 index d6b7ef3..0000000 --- a/logs/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore From 1dcaa83085dd6954f7218954b1a0fff8b70863dd Mon Sep 17 00:00:00 2001 From: levani Date: Fri, 21 Sep 2018 15:30:36 +0400 Subject: [PATCH 2/3] Update readme --- README.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/README.md b/README.md index 5af8418..f8939d5 100644 --- a/README.md +++ b/README.md @@ -39,3 +39,48 @@ for ($i = 0; $i < 20; $i++){ } ``` +## Logger Options ## + +
Log file creation types (const)
+```php +FILE_CREATE_TYPE_BY_TIME //recreate log file by time +FILE_CREATE_TYPE_BY_SIZE //recreate log file by size +``` +
Color
+```php +enableColors //colored text for logs , deafult value true +``` +
Log file recreation type
+```php +fileCreateType //log file creation type , default value "FILE_CREATE_TYPE_BY_TIME" +``` + +
Log file recreation units
+```php +Add one of this properties if file recreation type set to "FILE_CREATE_TYPE_BY_TIME" + +fileReCreateMinutes // (integer) +fileReCreateHours // (integer) +fileReCreateDays // (integer) +fileReCreateMonths // (integer) +fileReCreateYears // (integer) +``` +
Log file recreation size
+```php +Add this property if file recreation type set to "FILE_CREATE_TYPE_BY_SIZE" + +filReCreateSize = 900; //size in bytes +``` +
Log file attributes
+```php +logFilePath // full path to log file +logFileName // log file name "example.log" +logFileDateFormat // log file date format default value "Y_m_d" +logFileTemplate // log file template deafault value "{date}_{fileName}" +``` +
Log text attributes
+```php +logTextDateFormat // log text date format default value "Y-m-d H:i:s" +logTextTemplate // log text template default value "[ {date} | {type} ] - {message} " . PHP_EOL +``` + From 4209b669be8bd1c1c4ff831cbec75944b0157b4b Mon Sep 17 00:00:00 2001 From: levani Date: Fri, 21 Sep 2018 15:33:14 +0400 Subject: [PATCH 3/3] U[date readme --- README.md | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index f8939d5..f57ef8f 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ to the require section of your `composer.json` file. ## Basic usage ## -```php +``` include_once 'CliColor.php'; include_once 'CliLogger.php'; @@ -42,21 +42,25 @@ for ($i = 0; $i < 20; $i++){ ## Logger Options ##
Log file creation types (const)
-```php + +``` FILE_CREATE_TYPE_BY_TIME //recreate log file by time FILE_CREATE_TYPE_BY_SIZE //recreate log file by size ```
Color
-```php + +``` enableColors //colored text for logs , deafult value true ```
Log file recreation type
-```php + +``` fileCreateType //log file creation type , default value "FILE_CREATE_TYPE_BY_TIME" ```
Log file recreation units
-```php + +``` Add one of this properties if file recreation type set to "FILE_CREATE_TYPE_BY_TIME" fileReCreateMinutes // (integer) @@ -66,20 +70,23 @@ fileReCreateMonths // (integer) fileReCreateYears // (integer) ```
Log file recreation size
-```php + +``` Add this property if file recreation type set to "FILE_CREATE_TYPE_BY_SIZE" filReCreateSize = 900; //size in bytes ```
Log file attributes
-```php + +``` logFilePath // full path to log file logFileName // log file name "example.log" logFileDateFormat // log file date format default value "Y_m_d" logFileTemplate // log file template deafault value "{date}_{fileName}" ``` -
Log text attributes
-```php +
Log text attributes
+ +``` logTextDateFormat // log text date format default value "Y-m-d H:i:s" logTextTemplate // log text template default value "[ {date} | {type} ] - {message} " . PHP_EOL ```