PHP_SMART_HOME_V3/app/class/LogManager.php

40 lines
714 B
PHP
Raw Normal View History

2019-08-30 15:29:34 +00:00
<?php
/**
*
*/
class LogRecordType{
const WARNING = 'warning';
const ERROR = 'error';
const INFO = 'info';
}
class LogManager
{
private $logFile;
function __construct($fileName = "")
{
if ($fileName == ""){
2019-09-19 12:48:31 +00:00
$fileName = './app/logs/'. date("Y-m-d").'.log';
2019-08-30 15:29:34 +00:00
}
2019-09-19 12:48:31 +00:00
if(!is_dir("./app/logs/"))
2019-08-30 15:29:34 +00:00
{
2019-09-19 12:48:31 +00:00
mkdir("./app/logs/");
2019-08-30 15:29:34 +00:00
}
$this->logFile = fopen($fileName, "a") or die("Unable to open file!");
}
function write($value, $type = LogRecordType::ERROR){
2019-09-19 12:48:31 +00:00
$record = "[".date("H:m:s")."][".$type."]" . $value . "\n";
$record = Utilities::stringInsert($record,"\n",65);
2019-08-30 15:29:34 +00:00
fwrite($this->logFile, $record);
}
function __destruct(){
if (isset($this->logFile)) {
fclose($this->logFile);
}
}
}