Skip to content

Commit

Permalink
#32 - updated the LogProviderFile::backupFile() method to zip compres…
Browse files Browse the repository at this point in the history
…s the backup logfile once created
  • Loading branch information
alphadevx committed Nov 14, 2016
1 parent 40651de commit b02bc02
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Alpha/Util/File/FileUtils.php
Expand Up @@ -16,7 +16,7 @@
*
* @author John Collins <dev@alphaframework.org>
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License
* @copyright Copyright (c) 2015, John Collins (founder of Alpha Framework).
* @copyright Copyright (c) 2016, John Collins (founder of Alpha Framework).
* All rights reserved.
*
* <pre>
Expand Down Expand Up @@ -649,7 +649,7 @@ public static function copy($source, $dest)
}

/**
* Recursively compresses the contens of the source directory indicated to the desintation zip archive.
* Recursively compresses the contents of the source directory indicated to the destintation zip archive.
*
* @param string $source The path to the source directory or file.
* @param string $dest The destination zip file file.
Expand Down
23 changes: 14 additions & 9 deletions Alpha/Util/Logging/LogProviderFile.php
Expand Up @@ -4,6 +4,7 @@

use Alpha\Util\Config\ConfigProvider;
use Alpha\Exception\PHPException;
use Alpha\Util\File\FileUtils;

/**
* Generic log file class to encapsulate common file I/O and rendering calls.
Expand All @@ -12,7 +13,7 @@
*
* @author John Collins <dev@alphaframework.org>
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License
* @copyright Copyright (c) 2015, John Collins (founder of Alpha Framework).
* @copyright Copyright (c) 2016, John Collins (founder of Alpha Framework).
* All rights reserved.
*
* <pre>
Expand Down Expand Up @@ -66,7 +67,7 @@ class LogProviderFile implements LogProviderInterface
*
* @since 1.0
*/
private $MaxSize = 5;
private $maxSize = 5;

/**
* Set the file path.
Expand All @@ -83,13 +84,13 @@ public function setPath($path)
/**
* Set the max log size in megabytes.
*
* @param int $MaxSize
* @param int $maxSize
*
* @since 1.0
*/
public function setMaxSize($MaxSize)
public function setMaxSize($maxSize)
{
$this->MaxSize = $MaxSize;
$this->maxSize = $maxSize;
}

/**
Expand All @@ -104,7 +105,7 @@ public function writeLine($line)
$fp = fopen($this->path, 'a+');
fputcsv($fp, $line, ',', '"', '\\');

if ($this->checkFileSize() >= $this->MaxSize) {
if ($this->checkFileSize() >= $this->maxSize) {
$this->backupFile();
}
} catch (\Exception $e) {
Expand All @@ -122,7 +123,7 @@ public function writeLine($line)
throw new PHPException('Could not write to the CSV file ['.$this->path.']');
}

if ($this->checkFileSize() >= $this->MaxSize) {
if ($this->checkFileSize() >= $this->maxSize) {
$this->backupFile();
}
} catch (\Exception $e) {
Expand Down Expand Up @@ -160,10 +161,14 @@ private function backupFile()

// renames the logfile as the value of $backName
rename($this->path, $backName);
//creates a new log file, and sets it's permission for writting!

FileUtils::zip($backName, $backName.'.zip');
unlink($backName);

// creates a new log file, and sets it's permission for writing!
$fp = fopen($this->path, 'a+'); // remember set directory permissons to allow creation!
fclose($fp);
//sets the new permission to rw+:rw+:rw+
//s ets the new permission to rw+:rw+:rw+
chmod($this->path, 0666);
}

Expand Down

0 comments on commit b02bc02

Please sign in to comment.