Class: Build::CompactFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/build/logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(verbose: true) ⇒ CompactFormatter

Returns a new instance of CompactFormatter.



26
27
28
29
# File 'lib/build/logger.rb', line 26

def initialize(verbose: true)
	@start = Time.now
	@verbose = verbose
end

Instance Method Details

#call(severity, datetime, progname, message) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/build/logger.rb', line 58

def call(severity, datetime, progname, message)
	buffer = []
	
	if @verbose
		buffer << time_offset_string << ": "
	end
	
	if progname == 'shell' and Array === message
		buffer << format_command(message)
	else
		buffer << message
	end
	
	buffer << "\n"
	
	return buffer.join
end

#chdir_string(options) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/build/logger.rb', line 37

def chdir_string(options)
	if options[:chdir]
		" in #{options[:chdir]}"
	else
		""
	end
end

#format_command(arguments) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/build/logger.rb', line 45

def format_command(arguments)
	if arguments.last.is_a? Hash
		options = arguments.last
		arguments = arguments[0...-1]
	else
		options = {}
	end
	
	arguments = arguments.flatten.collect(&:to_s)
	
	Rainbow(arguments.join(' ')).blue + chdir_string(options)
end

#time_offset_stringObject



31
32
33
34
35
# File 'lib/build/logger.rb', line 31

def time_offset_string
	offset = Time.now - @start
	
	"T+#{offset.round(2).to_s.ljust(5)}"
end