import re


def parse_line(line):
    """
    Parse a log line to extract IP, path, status and length
    """
    # The common logfile format is as follows:
    # remotehost rfc931 authuser [date] "request" status bytes
    regex = re.compile(r'^(?P<ip>.*?) (?P<remote_log_name>.*?) '
                       r'(?P<userid>.*?) \[(?P<date>.*?)(?= ) '
                       r'(?P<timezone>.*?)\] \"(?P<request_method>.*?) '
                       r'(?P<path>.*?)(?P<request_version> HTTP/.*)?\" '
                       r'(?P<status>.*?) (?P<length>.*?)$')

    match = regex.match(line.rstrip('\n'))
    if match is not None:
        return (match.group('ip'), match.group('path'),
                match.group('status'), match.group('length'))