diff --git a/pandora_server/conf/pandora_server.conf.new b/pandora_server/conf/pandora_server.conf.new index 4b9b19f188..6dfa96e8c2 100644 --- a/pandora_server/conf/pandora_server.conf.new +++ b/pandora_server/conf/pandora_server.conf.new @@ -274,10 +274,13 @@ braa_retries 3 autocreate 1 # max_log_size: Specify max size of Pandora FMS server log file (1MB by default). If -# log file grows above this limit, is renamed to "pandora_server.log.old". +# log file grows above this limit, is renamed to "pandora_server.log.0". max_log_size 1048576 +# max_log_generation: Specify max generation count (between 1 and 9) of Pandora FMS server log files. +max_log_generation 1 + # max_queue_files (500 by default) # When server have more than max_queue_files in incoming directory, skips the read # the directory to avoid filesystem overhead. diff --git a/pandora_server/lib/PandoraFMS/Config.pm b/pandora_server/lib/PandoraFMS/Config.pm index f7c4e53a77..e89aff3ac8 100644 --- a/pandora_server/lib/PandoraFMS/Config.pm +++ b/pandora_server/lib/PandoraFMS/Config.pm @@ -286,6 +286,9 @@ sub pandora_load_config { # max log size (bytes) $pa_config->{'max_log_size'} = 1048576; + # max log generation + $pa_config->{'max_log_generation'} = 1; + # Ignore the timestamp in the XML and use the file timestamp instead $pa_config->{'use_xml_timestamp'} = 0; @@ -639,6 +642,9 @@ sub pandora_load_config { elsif ($parametro =~ m/^max_log_size\s([0-9]*)/i) { $pa_config->{'max_log_size'}= clean_blank($1); } + elsif ($parametro =~ m/^max_log_generation\s([1-9])/i) { + $pa_config->{'max_log_generation'}= clean_blank($1); + } elsif ($parametro =~ m/^wmi_threads\s([0-9]*)/i) { $pa_config->{'wmi_threads'}= clean_blank($1); } diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index 68c10a10be..708a874ca7 100644 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -466,7 +466,12 @@ sub logger ($$;$) { closelog(); } else { # Log rotation - rename ($file, $file.'.old') if (-e $file && (stat($file))[7] > $pa_config->{'max_log_size'}); + if (-e $file && (stat($file))[7] > $pa_config->{'max_log_size'}) { + foreach my $i (reverse 1..$pa_config->{'max_log_generation'}) { + rename ($file . "." . ($i - 1), $file . "." . $i); + } + rename ($file, "$file.0"); + } open (FILE, ">> $file") or die "[FATAL] Could not open logfile '$file'"; print FILE strftime ("%Y-%m-%d %H:%M:%S", localtime()) . " " . $pa_config->{'servername'} . $pa_config->{'servermode'} . " [V". $level ."] " . $message . "\n";