From e44c7b90d614be2177f7c788232a831b7ccfee5e Mon Sep 17 00:00:00 2001 From: meadsteve Date: Sun, 27 Oct 2013 14:21:08 +0000 Subject: [PATCH] All build logs calls now pass the build through as part of the context so this gets recorded in the log message. --- PHPCI/Builder.php | 5 ++++ PHPCI/Helper/LoggedBuildContextTidier.php | 31 +++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 PHPCI/Helper/LoggedBuildContextTidier.php diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index 2480dbe4..11e46082 100644 --- a/PHPCI/Builder.php +++ b/PHPCI/Builder.php @@ -246,6 +246,11 @@ class Builder implements LoggerAwareInterface if (!is_array($message)) { $message = array($message); } + + // The build is added to the context so the logger can use + // details from it if required. + $context['build'] = $this; + foreach ($message as $item) { $this->logger->log($level, $item, $context); } diff --git a/PHPCI/Helper/LoggedBuildContextTidier.php b/PHPCI/Helper/LoggedBuildContextTidier.php new file mode 100644 index 00000000..2a8a5e72 --- /dev/null +++ b/PHPCI/Helper/LoggedBuildContextTidier.php @@ -0,0 +1,31 @@ +tidyLoggedBuildContext(func_get_arg(0)); + } + + /** + * Removes the build object from the logged record and adds the ID as + * this is more useful to display. + * + * @param array $logRecord + * @return array + */ + protected function tidyLoggedBuildContext(array $logRecord) + { + if (isset($logRecord['context']['build'])) { + $build = $logRecord['context']['build']; + if ($build instanceof Build) { + $logRecord['context']['buildID'] = $build->getId(); + unset($logRecord['context']['build']); + } + } + return $logRecord; + } +} \ No newline at end of file