mirror of
https://github.com/tuxis-ie/nsedit.git
synced 2025-05-24 00:24:07 +03:00
Initial implementation of log rotation.
This commit is contained in:
parent
a8abca1121
commit
d1b817443c
4 changed files with 77 additions and 1 deletions
|
@ -277,6 +277,37 @@ function clearlogs() {
|
|||
writelog("Logtable truncated.");
|
||||
}
|
||||
|
||||
function rotatelogs() {
|
||||
global $logging, $logsdirectory;
|
||||
if ($logging !== TRUE)
|
||||
return FALSE;
|
||||
|
||||
if(!is_dir($logsdirectory) || !is_writable($logsdirectory)) {
|
||||
writelog("Logs directory cannot be written to.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
date_default_timezone_set('UTC');
|
||||
$filename = date("Y-m-d-His") . ".json";
|
||||
$file = fopen($logsdirectory . "/" . $filename, "x");
|
||||
|
||||
if($file === FALSE) {
|
||||
writelog("Can't create file for log rotation.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if(fwrite($file,json_encode(getlogs())) === FALSE) {
|
||||
writelog("Can't write to file for log rotation.");
|
||||
fclose($file);
|
||||
return FALSE;
|
||||
} else {
|
||||
fclose($file);
|
||||
clearlogs();
|
||||
return $filename;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function writelog($line) {
|
||||
global $logging;
|
||||
if ($logging !== TRUE)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue