From 83879b5d53c51586f6a8e18df4677b79cb410271 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 17 Jun 2016 13:48:35 +0200 Subject: [PATCH] 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 b4ccf143..4a99eae2 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 3cf7c2f4..e2a37cc4 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 1a3c73b6..5b69b5dc 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); } }