GrokResult as a dictionary
Marusyk opened this issue · 2 comments
Marusyk commented
Currently, the result is a list. This code:
Grok grok = new Grok("%{MONTHDAY:month}-%{MONTHDAY:day}-%{MONTHDAY:year} %{TIME:timestamp};%{WORD:id};%{LOGLEVEL:loglevel};%{WORD:func};%{GREEDYDATA:msg}");
string logs = @"06-21-19 21:00:13:589241;15;INFO;main;DECODED: 775233900043 DECODED BY: 18500738 DISTANCE: 1.5165
06-22-19 22:00:13:589265;156;WARN;main;DECODED: 775233900043 EMPTY DISTANCE: --------";
var grokResult = grok.Parse(logs);
foreach (var item in grokResult)
{
Console.WriteLine($"{item.Key} : {item.Value}");
}
will print :
month : 06
day : 21
year : 19
timestamp : 21:00:13:589241
id : 15
loglevel : INFO
func : main
msg : DECODED: 775233900043 DECODED BY: 18500738 DISTANCE: 1.5165
month : 06
day : 22
year : 19
timestamp : 22:00:13:589265
id : 156
loglevel : WARN
func : main
msg : DECODED: 775233900043 EMPTY DISTANCE: --------
It could be really useful to group the keys, e.g grokResult.AsDictionary();
to get:
month:
06
06
day:
21
21
year:
19
19
timestamp:
21:00:13:589241
21:00:13:589265
id:
15
156
loglevel:
INFO
WARN
func:
main
main
msg:
DECODED: 775233900043 DECODED BY: 18500738 DISTANCE: 1.5165
DECODED: 775233900043 EMPTY DISTANCE: --------
GioMaz commented
Can i take this one?