diff --git a/app/models/managers/LogManager.php b/app/models/managers/LogManager.php index edae6e8..27386a5 100644 --- a/app/models/managers/LogManager.php +++ b/app/models/managers/LogManager.php @@ -8,6 +8,7 @@ class LogManager { private $logFile; + private $filePath = null; private $logLevel = 1; public function __construct($fileName = "") @@ -15,12 +16,13 @@ class LogManager if ($fileName == ""){ $fileName = '../logs/'. date("Y-m-d").'.log'; } + if(!is_dir("../logs/")) { mkdir("../logs/"); } - $this->logFile = fopen($fileName, "a") or die("Unable to open file!"); + $this->filePath = $fileName; } public function setLevel($type = LogRecordTypess::WARNING){ @@ -28,6 +30,10 @@ class LogManager } public function write($value, $type = LogRecordTypess::ERROR){ + if ($this->logFile == null) { + $this->logFile = fopen($this->filePath, "a") or die("Unable to open file!"); + } + if ($type['level'] <= $this->logLevel) { $record = "[".date("H:m:s")."][".$type['identifier']."]" . $value . "\n"; fwrite($this->logFile, $record);