Skip to content

Commit 10eb2f3

Browse files
author
florian030
committed
rotate error.log daily (Fixes #5003)
1 parent 3498837 commit 10eb2f3

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

server/lib/classes/cron.d/200-logfiles.inc.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,18 @@ public function onRunJob() {
137137
}
138138
}
139139

140-
// rotate and compress the error.log when it exceeds a size of 10 MB
141-
$logfile = escapeshellcmd($rec['document_root'].'/' . $log_folder . '/error.log');
142-
if(is_file($logfile) && filesize($logfile) > 10000000) {
143-
exec("gzip -c $logfile > $logfile.1.gz");
144-
exec("cat /dev/null > $logfile");
140+
// rotate and compress the error.log
141+
$error_logfile = escapeshellcmd($rec['document_root'].'/' . $log_folder . '/error.log');
142+
// rename older files (move up by one)
143+
$num = $log_retention;
144+
while($num >= 1 && is_file($error_logfile . '.' . $num . '.gz')) {
145+
rename($error_logfile . '.' . $num . '.gz', $error_logfile . '.' . ($num + 1) . '.gz');
146+
$num--;
147+
}
148+
// compress current logfile
149+
if(is_file($error_logfile)) {
150+
exec("gzip -c $error_logfile > $error_logfile.1.gz");
151+
exec("cat /dev/null > $error_logfile");
145152
}
146153

147154
// delete logfiles after x days (default 30)

0 commit comments

Comments
 (0)