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){
|
2020-07-29 06:44:11 +00:00
|
|
|
$this->logLevel = $type['level'];
|
2020-07-28 07:02:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|