add preserve-switch to kv_parse

This commit is contained in:
TKE
2021-03-25 18:13:35 +01:00
parent e837160073
commit 2f195ac530

View File

@@ -5,6 +5,7 @@ import argparse
import sys
parser = argparse.ArgumentParser()
parser.add_argument("-p", "--preserve", action='store_true', help="preserve original logline in dict")
parser.add_argument('infile', nargs='?', type=argparse.FileType('r'), default=sys.stdin)
parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'), default=sys.stdout)
args = parser.parse_args()
@@ -20,8 +21,8 @@ for line in data:
matches=kv_pat.findall(line)
for match in matches:
line_dict[match[0]] = match[1].strip('"')
if args.preserve:
line_dict['original_logline'] = line
log.append(line_dict)
json.dump(log,args.outfile)