From 7bdd2a02e56f253543a4f18f6306a454d70dfe1c Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Mon, 7 Oct 2019 10:02:21 +0200 Subject: [PATCH] Added a string with information of the caller of pandora_server. Modified too an issue with security level messages --- pandora_server/lib/PandoraFMS/Tools.pm | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index e07a4e9ae6..4cb203d129 100755 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -640,19 +640,24 @@ sub logger ($$;$) { # Set the security level my $security_level = 'info'; if ($level < 2) { - $security = 'crit'; + $security_level = 'crit'; } elsif ($level < 5) { - $security = 'warn'; + $security_level = 'warn'; } openlog('pandora_server', 'ndelay', 'daemon'); syslog($security_level, $message); closelog(); } else { + # Obtain the script that invoke this log + my $parent_caller = ""; + if (($parent_caller = ( caller(2) )[1]) ne "") { + $parent_caller = " ** " . (split '/', $parent_caller)[-1] . " **:"; + } open (FILE, ">> $file") or die "[FATAL] Could not open logfile '$file'"; # Get an exclusive lock on the file (LOCK_EX) flock (FILE, 2); - print FILE strftime ("%Y-%m-%d %H:%M:%S", localtime()) . " " . (defined($pa_config->{'servername'}) ? $pa_config->{'servername'} : '') . " [V". $level ."] " . $message . "\n"; + print FILE strftime ("%Y-%m-%d %H:%M:%S", localtime()) . $parent_caller . " " . (defined($pa_config->{'servername'}) ? $pa_config->{'servername'} : '') . " [V". $level ."] " . $message . "\n"; close (FILE); } }