PHP_SMART_HOME_V3/app/models/managers/LogManager.php

43 lines
761 B
PHP
Raw Normal View History

2020-05-16 15:18:27 +00:00
<?php
/**
*
*/
2020-07-28 07:02:46 +00:00
2020-05-16 15:18:27 +00:00
class LogManager
{
private $logFile;
2020-07-28 07:02:46 +00:00
private $logLevel = 1;
public function __construct($fileName = "")
2020-05-16 15:18:27 +00:00
{
if ($fileName == ""){
$fileName = '../logs/'. date("Y-m-d").'.log';
}
if(!is_dir("../logs/"))
{
mkdir("../logs/");
}
2020-07-28 07:02:46 +00:00
2020-05-16 15:18:27 +00:00
$this->logFile = fopen($fileName, "a") or die("Unable to open file!");
}
2020-07-28 07:02:46 +00:00
public function setLevel($type = LogRecordTypess::WARNING){
$logLevel = $type['level'];
}
public function write($value, $type = LogRecordTypess::ERROR){
if ($type['level'] <= $this->logLevel) {
$record = "[".date("H:m:s")."][".$type['identifier']."]" . $value . "\n";
fwrite($this->logFile, $record);
}
2020-05-16 15:18:27 +00:00
}
2020-07-28 07:02:46 +00:00
public function __destruct(){
2020-05-16 15:18:27 +00:00
if (isset($this->logFile)) {
fclose($this->logFile);
}
}
}