def journald_json_formatter(output_file):
 accumulated = {}
 def handle_output_line(line):
  if line:
   (key, value) = line.split('=', 1)
   accumulated[key] = value
  elif accumulated:
   raw_message = accumulated.get('MESSAGE', '{}')
   try:
    message = json.loads(raw_message)
   except ValueError:
    message = dict(message=raw_message)
   message[u'_HOSTNAME'] = accumulated.get('_HOSTNAME', '<no hostname>')
   message[u'_PROCESS_NAME'] = accumulated.get('_SYSTEMD_UNIT', '<no unit>')
   output_file.write((json.dumps(message) + '\n'))
   accumulated.clear()
 return handle_output_line

def journald_json_formatter ( output_file ) : accumulated = { } def handle_output_line ( line ) : if line : ( key , value ) = line . split ( '=' , 1 ) accumulated [ key ] = value elif accumulated : raw_message = accumulated . get ( 'MESSAGE' , '{}' ) try : message = json . loads ( raw_message ) except ValueError : message = dict ( message = raw_message ) message [ u'_HOSTNAME' ] = accumulated . get ( '_HOSTNAME' , '<no hostname>' ) message [ u'_PROCESS_NAME' ] = accumulated . get ( '_SYSTEMD_UNIT' , '<no unit>' ) output_file . write ( ( json . dumps ( message ) + '\n' ) ) accumulated . clear ( ) return handle_output_line
create an output handler which turns journalds export format back into eliot json with extra fields to identify the log origin .