Log Clean Up "LogKeeper" initial

This commit is contained in:
JonatanRek 2020-02-13 13:53:58 +01:00
parent 1b5630215b
commit 4ab9ad9c7c
2 changed files with 23 additions and 2 deletions

View File

@ -39,7 +39,7 @@ Db::connect (DBHOST, DBUSER, DBPASS, DBNAME);
$json = file_get_contents('php://input'); $json = file_get_contents('php://input');
$obj = json_decode($json, true); $obj = json_decode($json, true);
$logManager->write("[API] Rest API request body \n" . $json, LogRecordType::INFO); $logManager->write("[API] Rest API request body \n" . $json, LogRecordType::INFO);
$logManager->write("[API] Rest API request body -> decodet to json \n" . var_export($obj), LogRecordType::INFO); //$logManager->write("[API] Rest API request body -> decodet to json \n" . var_dump($obj), LogRecordType::INFO);
//zabespecit proti Ddosu //zabespecit proti Ddosu
if (isset($obj['user']) && $obj['user'] != ''){ if (isset($obj['user']) && $obj['user'] != ''){
@ -71,9 +71,11 @@ if (DEBUGMOD != 1) {
//automationExecution //automationExecution
try { try {
AutomationManager::executeAll();
$fallbackManager = new FallbackManager(RANGES); $fallbackManager = new FallbackManager(RANGES);
$fallbackManager->check(); $fallbackManager->check();
AutomationManager::executeAll(); LogKeeper::purge(LOGTIMOUT);
die();
} catch (\Exception $e) { } catch (\Exception $e) {
$logManager->write("[Automation] Something happen during automation execution", LogRecordType::ERROR); $logManager->write("[Automation] Something happen during automation execution", LogRecordType::ERROR);
} }

View File

@ -9,6 +9,25 @@ class LogRecordType{
const INFO = 'info'; const INFO = 'info';
} }
class LogKeeper
{
function purge($days){
$todayFileName = date("Y-m-d").'.log';
$seconds = $days * 86400;
$logFiles = scandir('./app/logs/');
foreach ($logFiles as $key => $file) {
if (in_array($file,array(".","..", ".gitkeep", $todayFileName)))
{
continue;
}
if (filemtime($file) > $seconds) {
unlink('./app/logs/'.$file);
}
}
}
}
class LogManager class LogManager
{ {