human
Complete this python program:
def journald_json_formatter(output_file):
assistant
#Here is the Python code you requested.

    """Create an output handler which turns journald\s export format back into
    Eliot JSON with extra fields to identify the log origin.
    """
    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