lib/terraspace/logger.rb in terraspace-1.1.7 vs lib/terraspace/logger.rb in terraspace-2.0.0
- old
+ new
@@ -12,20 +12,47 @@
line = if @logdev.dev == $stdout || @logdev.dev == $stderr
msg # super simple format if stdout
else
super # use the configured formatter
end
- line =~ /\n$/ ? line : "#{line}\n"
+ out = line =~ /\n$/ ? line : "#{line}\n"
+ @@buffer << out
+ out
end
# Used to allow terraform output to always go to stdout
# Terraspace output goes to stderr by default
# See: terraspace/shell.rb
def stdout(msg, newline: true)
- if newline
- puts msg
- else
- print msg
+ out = newline ? "#{msg}\n" : msg
+ @@buffer << out
+ print out
+ end
+
+ def stdin_capture(text)
+ @@buffer << "#{text}\n"
+ @@stdin_capture = text
+ end
+
+ class << self
+ @@stdin_capture = ''
+ def stdin_capture
+ @@stdin_capture
+ end
+
+ @@buffer = []
+ def buffer
+ @@buffer
+ end
+
+ def logs
+ @@buffer.join('')
+ end
+
+ # for test framework
+ def clear
+ Terraspace::Command.reset_dispatch_command
+ @@buffer = []
end
end
end
end