[icinga-checkins] icinga.org: icingaweb2-module-director/master: JobRunner, JobHook: improve logging

git at icinga.org git at icinga.org
Fri Jun 17 13:48:53 CEST 2016


Module: icingaweb2-module-director
Branch: master
Commit: 83879b5d53c51586f6a8e18df4677b79cb410271
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=83879b5d53c51586f6a8e18df4677b79cb410271

Author: Thomas Gelf <thomas at gelf.net>
Date:   Fri Jun 17 13:48:35 2016 +0200

JobRunner, JobHook: improve logging

---

 library/Director/Hook/JobHook.php  |   23 ++++++-----------------
 library/Director/Job/ConfigJob.php |    5 +++--
 library/Director/Job/JobRunner.php |    2 ++
 3 files changed, 11 insertions(+), 19 deletions(-)

diff --git a/library/Director/Hook/JobHook.php b/library/Director/Hook/JobHook.php
index b4ccf14..4a99eae 100644
--- a/library/Director/Hook/JobHook.php
+++ b/library/Director/Hook/JobHook.php
@@ -3,6 +3,7 @@
 namespace Icinga\Module\Director\Hook;
 
 use Icinga\Application\Icinga;
+use Icinga\Application\Logger;
 use Icinga\Module\Director\Db;
 use Icinga\Module\Director\Objects\DirectorJob;
 use Icinga\Module\Director\Web\Form\QuickForm;
@@ -11,12 +12,6 @@ abstract class JobHook
 {
     private $db;
 
-    private $output   = array();
-
-    private $warnings = array();
-
-    private $errors   = array();
-
     private $jobDefinition;
 
     public static function getDescription(QuickForm $form)
@@ -84,12 +79,6 @@ abstract class JobHook
         return $this->db;
     }
 
-    protected function output($message)
-    {
-        $this->output[] = $message;
-        return $this;
-    }
-
     /**
      * printf helper method
      *
@@ -98,21 +87,21 @@ abstract class JobHook
      *
      * @return self
      */
-    protected function printf($message)
+    protected function info($message)
     {
-        $args = array_slice(func_get_args(), 1);
-        return $this->output(vsprintf($message, $args));
+        call_user_func_array(Loger::info, func_num_args());
+        return $this;
     }
 
     protected function warning($message)
     {
-        $this->warnings[] = $message;
+        call_user_func_array(Loger::warn, func_num_args());
         return $this;
     }
 
     protected function error($message)
     {
-        $this->errors[] = $message;
+        call_user_func_array(Logger::error, func_num_args());
         return $this;
     }
 }
diff --git a/library/Director/Job/ConfigJob.php b/library/Director/Job/ConfigJob.php
index 3cf7c2f..e2a37cc 100644
--- a/library/Director/Job/ConfigJob.php
+++ b/library/Director/Job/ConfigJob.php
@@ -101,11 +101,12 @@ class ConfigJob extends JobHook
         $api->wipeInactiveStages($db);
 
         $checksum = $config->getHexChecksum();
+        $this->info('Director ConfigJob ready to deploy "%s"', $checksum);
         if ($api->dumpConfig($config, $db)) {
-            $this->printf("Config '%s' has been deployed\n", $checksum);
+            $this->info('Director ConfigJob deployed config "%s"', $checksum);
             $api->collectLogFiles($db);
         } else {
-            $this->fail(sprintf("Failed to deploy config '%s'\n", $checksum));
+            throw new IcingaException('Failed to deploy config "%s"', $checksum);
         }
     }
 
diff --git a/library/Director/Job/JobRunner.php b/library/Director/Job/JobRunner.php
index 1a3c73b..5b69b5d 100644
--- a/library/Director/Job/JobRunner.php
+++ b/library/Director/Job/JobRunner.php
@@ -2,6 +2,7 @@
 
 namespace Icinga\Module\Director\Job;
 
+use Icinga\Application\Logger;
 use Icinga\Module\Director\Db;
 use Icinga\Module\Director\Objects\DirectorJob;
 
@@ -16,6 +17,7 @@ class JobRunner
     {
         foreach ($this->getConfiguredJobs() as $job) {
             if ($job->shouldRun()) {
+                Logger::info('Director JobRunner is starting "%s"', $job->job_name);
                 $this->run($job);
             }
         }



More information about the icinga-checkins mailing list