Skip to content

Commit

Permalink
Merge pull request #3 from apolloeleven/change-project-name
Browse files Browse the repository at this point in the history
Change project name
  • Loading branch information
sleemy1997 authored Oct 4, 2018
2 parents 97ca092 + c84980d commit 7cc772f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 41 deletions.
4 changes: 2 additions & 2 deletions CliColor.php → FileColor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
* Time: 3:17 PM
*/

namespace apollo11\cliLogger;
namespace apollo11\fileLogger;


class CliColor
class FileColor
{
// Text color options for log text
const F_BLACK = '0;30';
Expand Down
34 changes: 11 additions & 23 deletions CliLogger.php → FileLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
* Time: 12:39 PM
*/

namespace apollo11\cliLogger;
namespace apollo11\fileLogger;


class CliLogger
class FileLogger
{
//log file creation types
const FILE_CREATE_TYPE_BY_TIME = 1;
Expand Down Expand Up @@ -72,7 +72,7 @@ public function __construct($config)
* @return string
* @throws \Exception
*/
public function log($message, $fColor = CliColor::F_WHITE, $bColor = null, $type = 'LOG')
public function log($message, $fColor = FileColor::F_WHITE, $bColor = null, $type = 'LOG')
{
return $this->writeLog($this->processLogTextTemplate($message, $type), $fColor, $bColor);
}
Expand All @@ -88,7 +88,7 @@ public function log($message, $fColor = CliColor::F_WHITE, $bColor = null, $type
*/
public function error($message, $type = 'ERROR')
{
return $this->writeLog($this->processLogTextTemplate($message, $type), CliColor::F_RED);
return $this->writeLog($this->processLogTextTemplate($message, $type), FileColor::F_RED);
}


Expand All @@ -102,7 +102,7 @@ public function error($message, $type = 'ERROR')
*/
public function info($message, $type = 'INFO')
{
return $this->writeLog($this->processLogTextTemplate($message, $type), CliColor::F_LIGHT_BLUE);
return $this->writeLog($this->processLogTextTemplate($message, $type), FileColor::F_LIGHT_BLUE);
}


Expand All @@ -116,7 +116,7 @@ public function info($message, $type = 'INFO')
*/
public function success($message, $type = 'SUCCESS')
{
return $this->writeLog($this->processLogTextTemplate($message, $type), CliColor::F_LIGHT_GREEN);
return $this->writeLog($this->processLogTextTemplate($message, $type), FileColor::F_LIGHT_GREEN);
}


Expand All @@ -137,7 +137,7 @@ private function writeLog($message, $fColor, $bColor = null)
throw new \Exception('logFilePath is invalid');
}
if ($this->enableColors === true) {
$message = CliColor::getColoredString($message, $fColor, $bColor);
$message = FileColor::getColoredString($message, $fColor, $bColor);
}

$expiredLogFile = $this->checkFileCreation();
Expand Down Expand Up @@ -287,35 +287,23 @@ function deleteOldLogs()
*/
private function checkFileCreation()
{

$logFileName = $this->getLatestLogFile();
$logFilePath = $this->logFilePath . '/' . $logFileName;
$lastModified = filemtime($logFilePath);
$ex = time() - $lastModified;
$t = (
($this->fileReCreateMinutes * 60)
+ ($this->fileReCreateHours * 3600)
+ ($this->fileReCreateDays * 86400)
+ ($this->fileReCreateMonths * 2592000)
+ ($this->fileReCreateYears * 31536000)
);

if ($this->fileCreateType === self::FILE_CREATE_TYPE_BY_SIZE) {
if (file_exists($logFilePath) && filesize($logFilePath) >= $this->filReCreateSize) {
return $logFileName;
}
} else {
// TODO get first create date from file

if (file_exists($logFilePath) && ($ex >= $t)) {
} elseif ($this->fileCreateType === self::FILE_CREATE_TYPE_BY_TIME) {
$lasElementInDir = count(scandir($this->logFilePath));
$lastModifiedLogFileDate = strtotime(explode('_', scandir($this->logFilePath)[$lasElementInDir - 1])[0] . '+' . $this->fileReCreateDays . ' day');
if (file_exists($logFilePath) && strtotime(date($this->logFileDateFormat)) >= $lastModifiedLogFileDate) {
return $logFileName;
}
}

return false;
}


/**
* Get latest log
*
Expand Down
23 changes: 10 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# cli-logger
# File-logger

Installation
------------
Expand All @@ -8,24 +8,24 @@ The preferred way to install this extension is through [composer](http://getcomp
Either run

```
php composer.phar require --prefer-dist apollo11/cli-logger "*"
php composer.phar require --prefer-dist apollo11/file-logger "*"
```

or add

```
"apollo11/cli-logger": "*"
"apollo11/file-logger": "*"
```

to the require section of your `composer.json` file.

## Basic usage ##

```
include_once 'CliColor.php';
include_once 'CliLogger.php';
include_once 'FileColor.php';
include_once 'FileLogger.php';
$logger = new \apollo11\cliLogger\CliLogger([
$logger = new \apollo11\fileLogger\FileLogger([
'logFilePath' => dirname(__FILE__) . '/logs',
'logFileName' => 'test12.log',
'logFileDateFormat' => "Y_m_d_H_i_s",
Expand All @@ -35,7 +35,7 @@ $logger = new \apollo11\cliLogger\CliLogger([
]);
for ($i = 0; $i < 20; $i++){
$logger->log("My test $i", \apollo11\cliLogger\CliColor::F_WHITE, \apollo11\cliLogger\CliColor::B_GREEN);
$logger->log("My test $i", \apollo11\fileLogger\FileColor::F_WHITE, \apollo11\fileLogger\FileColor::B_GREEN);
}
```
Expand All @@ -58,16 +58,13 @@ enableColors //colored text for logs , deafult value true
fileCreateType //log file creation type , default value "FILE_CREATE_TYPE_BY_TIME"
```

<h5>Log file recreation units</h5>
<h5>Log file recreation days</h5>

```
Add one of this properties if file recreation type set to "FILE_CREATE_TYPE_BY_TIME"
Add 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>

Expand Down
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
{
"name": "apollo11/cli-logger",
"description": "Log any cli errors",
"name": "apollo11/file-logger",
"description": "Log any errors in file",
"license": "Apache-2.0",
"type": "library",
"authors": [
{
"name": "Giorgi Keshikashvili",
"email": "[email protected]"
},
{
"name": "Levan Khvedelidze",
"email": "[email protected]"
}
],
"autoload": {
"psr-4": { "apollo11\\cliLogger\\": "" }
"psr-4": { "apollo11\\fileLogger\\": "" }
},
"require": {
"php": ">=5.6"
Expand Down

0 comments on commit 7cc772f

Please sign in to comment.