@@ -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)
@@ -168,25 +175,26 @@ public function onRunJob() {
168175 // Rotate the ispconfig.log file
169176 //######################################################################################################
170177
171- // rotate the ispconfig.log when it exceeds a size of 10 MB
172- $ logfile = $ conf ['ispconfig_log_dir ' ].'/ispconfig.log ' ;
173- if (is_file ($ logfile ) && filesize ($ logfile ) > 10000000 ) {
174- exec ("gzip -c $ logfile > $ logfile.1.gz " );
175- exec ("cat /dev/null > $ logfile " );
176- }
177-
178- // rotate the cron.log when it exceeds a size of 10 MB
179- $ logfile = $ conf ['ispconfig_log_dir ' ].'/cron.log ' ;
180- if (is_file ($ logfile ) && filesize ($ logfile ) > 10000000 ) {
181- exec ("gzip -c $ logfile > $ logfile.1.gz " );
182- exec ("cat /dev/null > $ logfile " );
183- }
178+ $ num = 10 ;
184179
185- // rotate the auth.log when it exceeds a size of 10 MB
186- $ logfile = $ conf ['ispconfig_log_dir ' ].'/auth.log ' ;
187- if (is_file ($ logfile ) && filesize ($ logfile ) > 10000000 ) {
188- exec ("gzip -c $ logfile > $ logfile.1.gz " );
189- exec ("cat /dev/null > $ logfile " );
180+ $ ispconfig_logfiles = array ('ispconfig.log ' , 'cron.log ' , 'auth.log ' );
181+ foreach ($ ispconfig_logfiles as $ ispconfig_logfile ) {
182+ $ ispconfig_logfile = escapeshellcmd ($ conf ['ispconfig_log_dir ' ].'/ ' .$ ispconfig_logfile );
183+ // rename older files (move up by one)
184+ while ($ num >= 1 && is_file ($ ispconfig_logfile . '. ' . $ num . '.gz ' )) {
185+ rename ($ ispconfig_logfile . '. ' . $ num . '.gz ' , $ ispconfig_logfile . '. ' . ($ num + 1 ) . '.gz ' );
186+ $ num --;
187+ }
188+ // compress current logfile
189+ if (is_file ($ ispconfig_logfile )) {
190+ exec ("gzip -c $ ispconfig_logfile > $ ispconfig_logfile.1.gz " );
191+ exec ("cat /dev/null > $ ispconfig_logfile " );
192+ }
193+ // remove older logs
194+ while (is_file ($ ispconfig_logfile . '. ' . $ num . '.gz ' )) {
195+ @unlink ($ ispconfig_logfile . '. ' . $ num . '.gz ' );
196+ $ num ++;
197+ }
190198 }
191199
192200 //######################################################################################################
0 commit comments