import re
import sys

log = re.compile(r'(\d\d:\d\d:\d\d,\d\d\d) \[mess-id-([^]]*)\] (.*?)\s*$', re.S)

current = {}
buf = ''

fh = sys.stdin

while True:
    line = fh.readline()
    if line:
        m = log.match(line)
        if not m:
            buf += line
            continue
    if buf:
        m = log.match(buf)
        mess_time, mid, mess = m.groups()
        if mid in current:
            if mess == 'Outgoing SOAP response:':
                current[mid]['state'] = 'out'
            elif mess == 'Exit: LogHandler::invoke':
                if current[mid]['state'] == 'out':
                    print(mid, current[mid], "\n")
                    del current[mid]
                else:
                    current[mid]['state'] = ''
            else:
                if current[mid]['state'] and mess.startswith('<?xml'):
                    state = current[mid]['state']
                    current[mid][state] = mess
        else:
            if mess == 'Incoming SOAP request:':
                current[mid] = {'state': 'in'}
    if not line:
        break
    buf = line

fh.close()
