-
Notifications
You must be signed in to change notification settings - Fork 253
/
abstract.rb
50 lines (36 loc) · 1014 Bytes
/
abstract.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require 'forwardable'
module SSHKit
module Formatter
class Abstract
extend Forwardable
attr_reader :original_output
def_delegators :@original_output, :read, :rewind
def_delegators :@color, :colorize
def initialize(output)
@original_output = output
@color = SSHKit::Color.new(output)
end
%w(fatal error warn info debug).each do |level|
define_method(level) do |message|
write(LogMessage.new(Logger.const_get(level.upcase), message))
end
end
alias :log :info
def log_command_start(command)
write(command)
end
def log_command_data(command, _stream_type, _stream_data)
write(command)
end
def log_command_exit(command)
write(command)
end
def <<(obj)
write(obj)
end
def write(_obj)
raise "Abstract formatter should not be used directly, maybe you want SSHKit::Formatter::BlackHole"
end
end
end
end