INNER CODE UNIT · Python

build_pattern

lebinh/ngxtop · ngxtop/config_parser.py:126

def build_pattern(log_format):
    """
    Build regular expression to parse given format.
    :param log_format: format string to parse
    :return: regular expression to parse given format
    """
    if log_format == 'combined':
        log_format = LOG_FORMAT_COMBINED
    elif log_format == 'common':
        log_format = LOG_FORMAT_COMMON
    elif log_format == 'caddy':
        return 'caddy'  # Special case for Caddy JSON format
    pattern = re.sub(REGEX_SPECIAL_CHARS, r'\\\1', log_format)
    pattern = re.sub(REGEX_LOG_FORMAT_VARIABLE, '(?P<\\1>.*)', pattern)
    return re.compile(pattern)


def extract_variables(log_format):

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…