#740 --logfiles=8 and --logsize=10 (MB) options to netdisco-backend and netdisco-web

This commit is contained in:
Oliver Gorwits
2020-09-26 12:16:30 +01:00
parent 5839fd4404
commit 72934d394c
2 changed files with 22 additions and 4 deletions

View File

@@ -43,6 +43,15 @@ use Daemon::Control;
use Filesys::Notify::Simple;
use File::Copy;
use Getopt::Long;
Getopt::Long::Configure ("pass_through");
my ($logfiles, $logsize) = (8,10);
my $result = GetOptions(
'logfiles=i' => \$logfiles,
'logsize=i' => \$logsize,
);
use App::Netdisco::Environment;
my $config = ($ENV{PLACK_ENV} || $ENV{DANCER_ENVIRONMENT}) .'.yml';
@@ -156,13 +165,13 @@ sub rotate_logs {
my $child = shift;
return unless (-f $log_file) and
((-s $log_file) > (10 * 1024768));
((-s $log_file) > ($logsize * 1024768));
my @files = glob file($log_dir, '*');
foreach my $f (reverse sort @files) {
next unless $f =~ m/$log_file\.(\d)$/;
my $pos = $1;
unlink $f if $pos == 7;
unlink $f if $pos == ($logfiles - 1);
my $next = $pos + 1;
(my $newf = $f) =~ s/\.$pos$/.$next/;
rename $f, $newf;