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
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
105
106
107
108
|
# File 'lib/fluent/plugin/filter_nais_logformat.rb', line 15
def filter(tag, time, record)
r = nil
formats = @logformat
if record['kubernetes'].is_a?(Hash) && record['kubernetes']['annotations'].is_a?(Hash)
formats = record['kubernetes']['annotations']['nais_io/logformat']
end
unless formats.nil? || formats == ""
formats.split(',').each {|fmt|
if fmt == 'accesslog'
r = ::Nais::Log::Parser.parse_accesslog(record[@field])
unless r.nil?
r = r[0]
r[@field] = r.delete('request')
level = ::Nais::Log::Parser.loglevel_from_http_response(r['response_code'])
r['level'] = level unless level.nil?
end
elsif fmt == 'accesslog_with_processing_time'
r = ::Nais::Log::Parser.parse_accesslog_with_processing_time(record[@field])
unless r.nil?
r[@field] = r.delete('request')
level = ::Nais::Log::Parser.loglevel_from_http_response(r['response_code'])
r['level'] = level unless level.nil?
end
elsif fmt == 'accesslog_with_referer_useragent'
r = ::Nais::Log::Parser.parse_accesslog_with_referer_useragent(record[@field])
unless r.nil?
r[@field] = r.delete('request')
level = ::Nais::Log::Parser.loglevel_from_http_response(r['response_code'])
r['level'] = level unless level.nil?
end
elsif fmt == 'capnslog'
r = ::Nais::Log::Parser.parse_capnslog(record[@field])
unless r.nil?
r[@field] = r.delete('message')
end
elsif fmt == 'logrus'
r = ::Nais::Log::Parser.parse_logrus(record[@field])
unless r.nil?
r[@field] = r.delete('msg')
end
elsif fmt == 'gokit'
r = ::Nais::Log::Parser.parse_gokit(record[@field])
unless r.nil?
r['msg'] = r['err'] if r.has_key?('err') && !r.has_key?('msg')
r[@field] = r.delete('msg')
end
elsif fmt == 'rook'
r = ::Nais::Log::Parser.parse_rook(record[@field])
unless r.nil?
r[@field] = r.delete('message')
end
elsif fmt == 'redis'
r = ::Nais::Log::Parser.parse_redis(record[@field])
unless r.nil?
r[@field] = r.delete('message')
end
elsif fmt == 'coredns'
r = ::Nais::Log::Parser.parse_coredns(record[@field])
unless r.nil?
r[@field] = r.delete('message')
end
elsif fmt == 'simple'
r = ::Nais::Log::Parser.parse_simple(record[@field])
unless r.nil?
r[@field] = r.delete('message')
end
elsif fmt == 'glog'
r = ::Nais::Log::Parser.parse_glog(record[@field])
unless r.nil?
r['source'] = r['file']+':'+r.delete('line')
r['component'] = r.delete('file')
r[@field] = r.delete('message')
end
elsif fmt == 'influxdb'
r = ::Nais::Log::Parser.parse_influxdb(record[@field])
unless r.nil?
r[@field] = r.delete('message')
if r['component'] == 'httpd'
level = ::Nais::Log::Parser.loglevel_from_http_response(r['response_code'])
r['level'] = level unless level.nil?
end
end
elsif fmt == 'log15'
::Nais::Log::Parser.remap_log15(record)
end
break unless r.nil?
}
end
if r.nil?
record
else
record.merge(r)
end
end
|