From d923004a2b8345344a23ab0c27da1d97b9f05c4a Mon Sep 17 00:00:00 2001 From: Kimmo Lehto Date: Fri, 29 Mar 2019 09:57:02 +0200 Subject: [PATCH 1/2] Enable debug output for a selected phase only --- lib/pharos/logging.rb | 4 ++++ lib/pharos/phase_manager.rb | 3 +++ 2 files changed, 7 insertions(+) diff --git a/lib/pharos/logging.rb b/lib/pharos/logging.rb index 796881d8e..8224c36e2 100644 --- a/lib/pharos/logging.rb +++ b/lib/pharos/logging.rb @@ -12,6 +12,10 @@ def self.debug! @debug = true end + def self.no_debug! + @debug = false + end + def self.format_exception(exc, severity = "ERROR") if !ENV['DEBUG'].to_s.empty? || severity == "DEBUG" backtrace = "\n #{exc.backtrace.join("\n ")}" diff --git a/lib/pharos/phase_manager.rb b/lib/pharos/phase_manager.rb index b46b84d21..3510c54a0 100644 --- a/lib/pharos/phase_manager.rb +++ b/lib/pharos/phase_manager.rb @@ -93,11 +93,14 @@ def apply(phase_class, hosts, parallel: false, **options) phases = hosts.map { |host| prepare_phase(phase_class, host, **options) } run(phases, parallel: parallel) do |phase| + Pharos::Logging.debug! if ENV['DEBUG'].to_s == phase.class.name.split('::').last + start = Time.now phase.call phase.logger.info 'Completed phase in %.2fs' % { duration: Time.now - start } + Pharos::Logging.no_debug! if ENV['DEBUG'].to_s == phase.class.name.split('::').last end end end From 7700a8c0288316f1f4d76d2cef01e4fe53123fd9 Mon Sep 17 00:00:00 2001 From: Kimmo Lehto Date: Fri, 29 Mar 2019 10:06:18 +0200 Subject: [PATCH 2/2] Extra space. --- lib/pharos/phase_manager.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pharos/phase_manager.rb b/lib/pharos/phase_manager.rb index 3510c54a0..a90c80943 100644 --- a/lib/pharos/phase_manager.rb +++ b/lib/pharos/phase_manager.rb @@ -93,7 +93,7 @@ def apply(phase_class, hosts, parallel: false, **options) phases = hosts.map { |host| prepare_phase(phase_class, host, **options) } run(phases, parallel: parallel) do |phase| - Pharos::Logging.debug! if ENV['DEBUG'].to_s == phase.class.name.split('::').last + Pharos::Logging.debug! if ENV['DEBUG'].to_s == phase.class.name.split('::').last start = Time.now