This commit is contained in:
GamerClassN7 2021-04-05 10:46:27 +02:00
parent 49f2354908
commit f80b9a6b43

View File

@ -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);