Skip to content

Instantly share code, notes, and snippets.

@bjcubsfan
Forked from jhaubrich/reclog_objectifier.py
Last active December 15, 2015 18:48
Show Gist options
  • Save bjcubsfan/5305978 to your computer and use it in GitHub Desktop.
Save bjcubsfan/5305978 to your computer and use it in GitHub Desktop.
def objectify(frame):
""" yeilds one parsed object defined by the parsers in
the waas library.
"""
parsers = {'SP': sp_log.parse,
'CP': cp_log.parse,
'WAAS': waas_log.parse,
}
log_source = frame['log_type']
if log_source in parsers:
parse = parsers[ log_source ]
for [(raw_line, channel, msg) for raw_line in frame['lines'] for channel, msg in parse(raw_line)]:
if channel:
msg.update({'site': frame['site_name']})
yield {'channel': log_source + '.' + channel,
'msg': msg}
else: # channel was None
yield {'channel': log_source + '.' + 'UNPARSED',
'msg': {'line': raw_line,
'site': frame['site_name']}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment