Class: SSHKit::Formatter::PrettyHost
- Inherits:
-
Abstract
- Object
- Abstract
- SSHKit::Formatter::PrettyHost
- Defined in:
- lib/pretty_host.rb
Constant Summary collapse
- LEVEL_NAMES =
%w{ DEBUG INFO WARN ERROR FATAL }.freeze
- LEVEL_COLORS =
[:black, :blue, :yellow, :red, :red].freeze
Instance Method Summary collapse
- #log_command_data(command, stream_type, stream_data) ⇒ Object
- #log_command_exit(command) ⇒ Object
- #log_command_start(command) ⇒ Object
- #write(obj) ⇒ Object
Instance Method Details
#log_command_data(command, stream_type, stream_data) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/pretty_host.rb', line 25 def log_command_data(command, stream_type, stream_data) color = \ case stream_type when :stdout then :green when :stderr then :red else raise "Unrecognised stream_type #{stream_type}, expected :stdout or :stderr" end (Logger::DEBUG, colorize("\t#{stream_data}".chomp, color), command.host) end |
#log_command_exit(command) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/pretty_host.rb', line 35 def log_command_exit(command) runtime = sprintf('%5.3f seconds', command.runtime) successful_or_failed = command.failure? ? colorize('failed', :red, :bold) : colorize('successful', :green, :bold) = "Finished in #{runtime} with exit status #{command.exit_status} (#{successful_or_failed})." (command.verbosity, , command.host) end |
#log_command_start(command) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/pretty_host.rb', line 18 def log_command_start(command) host_prefix = command.host.user ? "as #{colorize(command.host.user, :blue)}@" : 'on ' = "Running #{colorize(command, :yellow, :bold)} #{host_prefix}#{colorize(command.host, :blue)}" (command.verbosity, , command.host) (Logger::DEBUG, "Command: #{colorize(command.to_command, :blue)}", command.host) end |
#write(obj) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/pretty_host.rb', line 10 def write(obj) if obj.kind_of?(SSHKit::LogMessage) (obj.verbosity, obj.to_s) else raise "write only supports formatting SSHKit::LogMessage, called with #{obj.class}: #{obj.inspect}" end end |