def METHOD_NAME(output):
  """Filters log output. Removes debug info, etc and normalize output."""
  if not output:
    return ''
  filtered_output = ''
  last_process_tuple = (None, None)
  for line in output.splitlines():
    if not is_line_valid(line):
      continue
    # To parse frames like:
    # E/v8      (18890): Error installing extension 'v8/LoadTimes'.
    # {log_level}/{process_name}({process_id}): {message}
    m_line = re.match(r'^[VDIWEFS]/(.+)\(\s*(\d+)\)[:](.*)$', line)
    if not m_line:
      logs.log_error('Failed to parse logcat line: %s' % line)
      continue
    process_name = m_line.group(1).strip()
    process_id = int(m_line.group(2))
    filtered_line = m_line.group(3).rstrip()[1:]
    # Process Android crash stack frames and convert into sanitizer format.
    m_crash_state = re.match(r'\s*#([0-9]+)\s+pc\s+([xX0-9a-fA-F]+)\s+(.+)',
                             filtered_line)
    if m_crash_state:
      frame_no = int(m_crash_state.group(1))
      frame_address = m_crash_state.group(2)
      frame_binary = m_crash_state.group(3).strip()
      # Ignore invalid frames, helps to prevent errors
      # while symbolizing.
      if '<unknown>' in frame_binary:
        continue
      # Normalize frame address.
      if not frame_address.startswith('0x'):
        frame_address = '0x%s' % frame_address
      # Separate out the function argument.
      frame_binary = (frame_binary.split(' '))[0]
      # Normalize line into the same sanitizer tool format.
      filtered_line = ('    #%d %s (%s+%s)' % (frame_no, frame_address,
                                               frame_binary, frame_address))
    # Process Chrome crash stack frames and convert into sanitizer format.
    # Stack frames don't have paranthesis around frame binary and address, so
    # add it explicitly to allow symbolizer to catch it.
    m_crash_state = re.match(
        r'\s*#([0-9]+)\s+([xX0-9a-fA-F]+)\s+([^(]+\+[xX0-9a-fA-F]+)$',
        filtered_line)
    if m_crash_state:
      frame_no = int(m_crash_state.group(1))
      frame_address = m_crash_state.group(2)
      frame_binary_and_address = m_crash_state.group(3).strip()
      filtered_line = ('    #%d %s (%s)' % (frame_no, frame_address,
                                            frame_binary_and_address))
    # Add process number if changed.
    current_process_tuple = (process_name, process_id)
    if current_process_tuple != last_process_tuple:
      filtered_output += '--------- %s (%d):\n' % (process_name, process_id)
      last_process_tuple = current_process_tuple
    filtered_output += filtered_line + '\n'
  return filtered_output