]> git.ipfire.org Git - people/stevee/guardian.git/blobdiff - guardian
Pass logger object to the mainsettings hash for a usage
[people/stevee/guardian.git] / guardian
index da9665cc8e8fb0d561655722707a66f72e3e510d..9245f9004827548fda1f18cecb747c1c11e85bdd 100644 (file)
--- a/guardian
+++ b/guardian
@@ -73,6 +73,10 @@ my %mainsettings = &Guardian::Config::UseConfig($cmdargs{"config"});
 my $logger = Guardian::Logger->New(%mainsettings);
 $logger->Log("debug", "Logger successfully initialized...");
 
+# Add the logger object to the mainsettings for passing
+# it to the modules.
+$mainsettings{Logger} = $logger;
+
 # Redirect perls "die" messages to the logger before exiting.
 $SIG{__DIE__} = sub { $logger->Log("err", "@_"); };
 
@@ -82,7 +86,7 @@ my %monitored_files :shared = ();
 
 # Create the main queue. It is used to store and process all events which are
 # reported and enqueued by the worker threads.
-my $queue :shared = new Thread::Queue or die "Could not create new, empty queue. $!\n";;
+my $queue :shared = new Thread::Queue or die "Could not create new, empty queue. $!";;
 
 # Array to store all currently running worker objects.
 # (Does not include the socket thread)
@@ -160,10 +164,10 @@ sub Worker ($) {
        $SIG{'KILL'} = sub { threads->exit(); };
 
        # Create inotify watcher.
-       my $watcher = new Linux::Inotify2 or die "Could not use inotify. $!\n";
+       my $watcher = new Linux::Inotify2 or die "Could not use inotify. $!";
 
        # Monitor the specified file.
-       $watcher->watch("$file", IN_MODIFY) or die "Could not monitor $file. $!\n";
+       $watcher->watch("$file", IN_MODIFY) or die "Could not monitor $file. $!";
 
        # Switch watcher into non-blocking mode.
        $watcher->blocking(0);
@@ -182,7 +186,7 @@ sub Worker ($) {
                        my $fileposition = $monitored_files{$file};
 
                        # Open the file.
-                       open (FILE, $file) or die "Could not open $file. $!\n";
+                       open (FILE, $file) or die "Could not open $file. $!";
 
                        # Seek to the last known position.
                        seek (FILE, $fileposition, 0);
@@ -339,6 +343,12 @@ sub Reload () {
        # Re-read configuration file.
        %mainsettings = &Guardian::Config::UseConfig($cmdargs{"config"});
 
+       # Update Logger settings.
+       $logger = Guardian::Logger->Update(%mainsettings);
+
+       # Update logger object in mainsettings hash.
+       $mainsettings{Logger} = $logger;
+
        # Re-generate hash of monitored files.
        %monitored_files = &Guardian::Base::GenerateMonitoredFiles(\%mainsettings, \%monitored_files);