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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/fluent/auditify/reporter/console.rb', line 24
def run(charges, logger=nil)
charges.each do |entry|
message = entry.first
options = entry.last
if options[:line] and options[:content]
if @options[:format] == :auto
lines = file_get_contents(options[:path])
min = options[:line] - 2 > 0 ? options[:line] - 2 : 0
max = options[:line] + 2 < lines.size ? options[:line] + 2 : lines.size - 1
content = ""
suggested = ""
min.upto(max).each_with_index do |line, index|
content << "#{min + index + 1}: #{lines[min + index].chomp}\n"
if options[:suggest] and options[:line] == min + index + 1
suggested << "#{min + index + 1}: #{options[:suggest].chomp}\n"
else
suggested << "#{min + index + 1}: #{lines[min + index].chomp}\n"
end
end
if options[:suggest]
diff_content = ''
Diff::LCS.sdiff(content.chars, suggested.chars).each do |change|
case change.action
when '-'
diff_content << Pastel.new.red(change.old_element)
when '+'
diff_content << Pastel.new.green(change.new_element)
else
diff_content << change.old_element
end
end
@logger.error("#{bomb} [plugin:#{options[:plugin]},category:#{options[:category]}] #{message} at #{options[:path]}:#{options[:line]}\n#{diff_content}")
else
@logger.error("#{bomb} [plugin:#{options[:plugin]},category:#{options[:category]}] #{message} at #{options[:path]}:#{options[:line]}\n#{content}")
end
else
@logger.error("#{bomb} [plugin:#{options[:plugin]},category:#{options[:category]}] #{message} at #{options[:path]}:#{options[:line]}: #{options[:content]}")
end
else
@logger.error("#{bomb} [plugin:#{options[:plugin]},category:#{options[:category]}] #{message} at #{options[:path]}")
end
end
end
|