Skip to content

Commit da0a817

Browse files
author
Marius Cramer
committed
Added cron log rotation and compression
1 parent b26653b commit da0a817

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,30 @@ public function onRunJob() {
112112
exec("gzip -c $logfile > $logfile.gz");
113113
unlink($logfile);
114114
}
115+
116+
$cron_logfiles = array('cron.log', 'cron_error.log', 'cron_wget.log');
117+
foreach($cron_logfiles as $cron_logfile) {
118+
$cron_logfile = escapeshellcmd($rec['document_root'].'/' . $log_folder . '/' . $cron_logfile);
119+
120+
// rename older files (move up by one)
121+
$num = 7;
122+
while($num >= 1 && is_file($cron_logfile . '.' . $num . '.gz')) {
123+
rename($cron_logfile . '.' . $num . '.gz', $cron_logfile . '.' . ($num + 1) . '.gz');
124+
$num--;
125+
}
126+
127+
// compress current logfile
128+
if(is_file($cron_logfile) && filesize($cron_logfile) > 10000000) {
129+
exec("gzip -c $cron_logfile > $cron_logfile.1.gz");
130+
exec("cat /dev/null > $cron_logfile");
131+
}
132+
// remove older logs
133+
$num = 7;
134+
while(is_file($cron_logfile . '.' . $num . '.gz')) {
135+
@unlink($cron_logfile . '.' . $num . '.gz');
136+
$num++;
137+
}
138+
}
115139

116140
// rotate and compress the error.log when it exceeds a size of 10 MB
117141
$logfile = escapeshellcmd($rec['document_root'].'/' . $log_folder . '/error.log');

0 commit comments

Comments
 (0)