Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	CliLogger.php
#	README.md
  • Loading branch information
sleemy1997 committed Sep 24, 2018
2 parents eabe757 + 0387780 commit 8822067
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CliColor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down
47 changes: 45 additions & 2 deletions CliLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,29 @@

class CliLogger
{

//log file creation types
const FILE_CREATE_TYPE_BY_TIME = 1;

const FILE_CREATE_TYPE_BY_SIZE = 2;


public $saveLatestFileNumber = 1;

//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;
Expand Down Expand Up @@ -57,11 +61,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')
{
Expand All @@ -70,9 +79,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')
{
Expand All @@ -81,9 +93,12 @@ public function error($message, $type = 'ERROR')


/**
* Log info
*
* @param $message
* @param string $type
* @return string
* @throws \Exception
*/
public function info($message, $type = 'INFO')
{
Expand All @@ -92,9 +107,12 @@ public function info($message, $type = 'INFO')


/**
* Log success
*
* @param $message
* @param string $type
* @return string
* @throws \Exception
*/
public function success($message, $type = 'SUCCESS')
{
Expand All @@ -103,6 +121,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
Expand Down Expand Up @@ -135,6 +157,10 @@ private function writeLog($message, $fColor, $bColor = null)


/**
* Constructor configuration
*
* Returns configuration object for constructor
*
* @param $object
* @param $properties
* @return mixed
Expand All @@ -150,6 +176,10 @@ private function configure($object, $properties)


/**
* Log file template
*
* Returns template for log file with chosen configuration
*
* @param $expiredLogFile
* @return bool|mixed|string
*/
Expand Down Expand Up @@ -188,6 +218,9 @@ private function processFileTemplate($expiredLogFile)


/**
* Log text template
*
* Returns template for log text with chosen configuration
* @param $message
* @param string $type
* @return string
Expand Down Expand Up @@ -244,6 +277,12 @@ function deleteOldLogs()


/**
* 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()
Expand Down Expand Up @@ -278,6 +317,10 @@ private function checkFileCreation()


/**
* Get latest log
*
* Return latest log file from log directory
*
* @return bool|mixed
*/
private function getLatestLogFile()
Expand Down
54 changes: 53 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ to the require section of your `composer.json` file.

## Basic usage ##

```php
```
include_once 'CliColor.php';
include_once 'CliLogger.php';
Expand All @@ -39,6 +39,58 @@ for ($i = 0; $i < 20; $i++){
}
```
## Logger Options ##

<h5>Log file creation types (const)</h5>

```
FILE_CREATE_TYPE_BY_TIME //recreate log file by time
FILE_CREATE_TYPE_BY_SIZE //recreate log file by size
```
<h5>Color</h5>

```
enableColors //colored text for logs , deafult value true
```
<h5>Log file recreation type</h5>

```
fileCreateType //log file creation type , default value "FILE_CREATE_TYPE_BY_TIME"
```

<h5>Log file recreation units</h5>

```
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)
```
<h5>Log file recreation size</h5>

```
Add this property if file recreation type set to "FILE_CREATE_TYPE_BY_SIZE"
filReCreateSize = 900; //size in bytes
```
<h5>Log file attributes</h5>

```
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}"
```
<h5>Log text attributes</h5>

```
logTextDateFormat // log text date format default value "Y-m-d H:i:s"
logTextTemplate // log text template default value "[ {date} | {type} ] - {message} " . PHP_EOL
```


For delete log file every x day use:

Expand Down
2 changes: 0 additions & 2 deletions logs/.gitignore

This file was deleted.

0 comments on commit 8822067

Please sign in to comment.