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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/fluent/plugin/filter_mule.rb', line 34
def filter(tag, time, record)
text = record['message']
puts "TEXT: " + text
match = text.match(/^(?<log_level>[\w]+)\s(?<log_time>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2},\d{3})\s\[(?<thread>.+)\]\s(?<position>[^:]+):\s(?<kv_pairs>.*?)\s?(?<payload>payload=.*)?$/)
if match.nil?
puts 'match is nil'
return record
end
puts '1'
if match.names.include? 'log_level'
record['mule_log_level'] = match['log_level']
end
puts '2'
if match.names.include? 'log_time'
record['mule_log_time'] = match['log_time']
end
puts '3'
if match.names.include? 'thread'
record['mule_thread'] = match['thread']
end
puts '4'
if match.names.include? 'position'
record['mule_position'] = match['position']
end
puts '5'
if match.names.include? 'kv_pairs'
kv_match = match['kv_pairs'].match(/(\w+)=([\w|-]+)\s/)
if kv_match == nil
puts 'Couldn\'t find kv pairs'
return record
end
match['kv_pairs'].split(@kv_delimiter).each { |kv|
k, v = kv.split(@kv_char, 2)
record['mule_' + k] = v
}
end
puts '6'
if (match.names.include? 'payload') && !match['payload'].nil?
puts '6.1'
k, v = match['payload'].split('=', 2)
puts '6.2'
record['mule_' + k] = v
end
puts '7'
puts 'record[log_time]: ' + record['mule_log_time']
puts 'record[log_time].nil?: ' + record['mule_log_time'].nil?.to_s
puts 'timeParse?: ' + @time_parse.to_s
if @time_parse && !record['log_time'].nil?
puts '7.1'
new_time = @time_parser.parse(record['mule_log_time'])
record.delete('time')
record['time'] = current_time
end
puts '8'
record.delete('message')
puts '9'
record
end
|