<commit_before>// Woodlot utility library

'use strict';

var DEFAULT_JSON_SPACING = require('./constants').DEFAULT_JSON_SPACING,
    DEFAULT_SEPARATOR = require('./constants').DEFAULT_SEPARATOR,
    foregroundGreen = require('./stdoutColors').foregroundGreen,
    foregroundBlue = require('./stdoutColors').foregroundBlue,
    foregroundYellow = require('./stdoutColors').foregroundYellow,
    foregroundRed = require('./stdoutColors').foregroundRed,
    foregroundCyan = require('./stdoutColors').foregroundCyan,
    APACHE_FORMAT_REGEX = require('./constants').STDOUT_FORMAT_REGEX.APACHE,
    JSON_FORMAT_REGEX = require('./constants').STDOUT_FORMAT_REGEX.JSON,
    TEXT_FORMAT_REGEX = require('./constants').STDOUT_FORMAT_REGEX.TEXT,
    CUSTOMLEVELJSON_REGEX = require('./constants').STDOUT_FORMAT_REGEX.CUSTOMLEVELJSON;

// Function to get log format based on Woodlot passed config
function getLogFormat(config) {
    if (config.format && config.format.type) {
        return config.format.type.toLowerCase();
    }
    return 'json';
};

// Function to get JSON format spacing value 
function getFormatSpacing(config) {
    var format = getLogFormat(config);

    // Get format spacing only for JSON type
    if (format === 'json') {
        if (config.format && config.format.options && ('spacing' in config.format.options)) {
            var spacing = parseInt(config.format.options.spacing, 10);

            if (isNaN(spacing)) {
                return config.format.options.spacing;
            }

            return spacing;
        }
        return DEFAULT_JSON_SPACING;
    }
    return null;
};

// Function to colorize request status code in stdout
function colorizeStatusCode(statusCode) {
    if (statusCode >= 200 && statusCode < 300) {

        return foregroundGreen(statusCode);

    } else if (statusCode >= 300 && statusCode < 400) {

        return foregroundBlue(statusCode);

    } else if (statusCode >= 400 && statusCode < 500) {

        return foregroundYellow(statusCode);

    } else {

        return foregroundRed(statusCode);

    }
};

// Function to colorize log level in stdout
function colorizeLogLevel(level) {
    switch (level.toLowerCase()) {
        case 'debug':
            return foregroundBlue(level);
        case 'warn':
            return foregroundYellow(level);
        case 'err':
            return foregroundRed(level);
        case 'info':
        default:
            return foregroundGreen(level);
    }
};

// Function to colorize apache log format
function colorizeStdoutFormat(log, format) {
    switch (format.toLowerCase()) {
        case 'combined':
        case 'common':
            var statusCodeIndex = log.match(APACHE_FORMAT_REGEX).index,
                statusCodeValue = log.substr(statusCodeIndex, 4),
                color = colorizeStatusCode(statusCodeValue);

            return log.replace(APACHE_FORMAT_REGEX, color);

        case 'text':
            var logLevel = log.match(TEXT_FORMAT_REGEX)[0],
                colorizedLog = log.replace(logLevel, colorizeLogLevel(logLevel));

            return colorizedLog;

        case 'customleveljson':
            var levelIndex = log.match(CUSTOMLEVELJSON_REGEX).index,
                colorizedLog = colorizeLogLevel(log.substr(levelIndex + 10, 5).replace(/['"]+/g, ''));

            return log.replace(CUSTOMLEVELJSON_REGEX, "level: " + '"' + colorizedLog + '"');<commit_msg>Custom 'err' level log matching bug fix<commit_after>// Woodlot utility library

'use strict';

var DEFAULT_JSON_SPACING = require('./constants').DEFAULT_JSON_SPACING,
    DEFAULT_SEPARATOR = require('./constants').DEFAULT_SEPARATOR,
    foregroundGreen = require('./stdoutColors').foregroundGreen,
    foregroundBlue = require('./stdoutColors').foregroundBlue,
    foregroundYellow = require('./stdoutColors').foregroundYellow,
    foregroundRed = require('./stdoutColors').foregroundRed,
    foregroundCyan = require('./stdoutColors').foregroundCyan,
    APACHE_FORMAT_REGEX = require('./constants').STDOUT_FORMAT_REGEX.APACHE,
    JSON_FORMAT_REGEX = require('./constants').STDOUT_FORMAT_REGEX.JSON,
    TEXT_FORMAT_REGEX = require('./constants').STDOUT_FORMAT_REGEX.TEXT,
    CUSTOMLEVELJSON_REGEX = require('./constants').STDOUT_FORMAT_REGEX.CUSTOMLEVELJSON;

// Function to get log format based on Woodlot passed config
function getLogFormat(config) {
    if (config.format && config.format.type) {
        return config.format.type.toLowerCase();
    }
    return 'json';
};

// Function to get JSON format spacing value 
function getFormatSpacing(config) {
    var format = getLogFormat(config);

    // Get format spacing only for JSON type
    if (format === 'json') {
        if (config.format && config.format.options && ('spacing' in config.format.options)) {
            var spacing = parseInt(config.format.options.spacing, 10);

            if (isNaN(spacing)) {
                return config.format.options.spacing;
            }

            return spacing;
        }
        return DEFAULT_JSON_SPACING;
    }
    return null;
};

// Function to colorize request status code in stdout
function colorizeStatusCode(statusCode) {
    if (statusCode >= 200 && statusCode < 300) {

        return foregroundGreen(statusCode);

    } else if (statusCode >= 300 && statusCode < 400) {

        return foregroundBlue(statusCode);

    } else if (statusCode >= 400 && statusCode < 500) {

        return foregroundYellow(statusCode);

    } else {

        return foregroundRed(statusCode);

    }
};

// Function to colorize log level in stdout
function colorizeLogLevel(level) {
    switch (level.toLowerCase()) {
        case 'debug':
            return foregroundBlue(level);
        case 'warn':
            return foregroundYellow(level);
        case 'err':
            return foregroundRed(level);
        case 'info':
        default:
            return foregroundGreen(level);
    }
};

// Function to colorize apache log format
function colorizeStdoutFormat(log, format) {
    switch (format.toLowerCase()) {
        case 'combined':
        case 'common':
            var statusCodeIndex = log.match(APACHE_FORMAT_REGEX).index,
                statusCodeValue = log.substr(statusCodeIndex, 4),
                color = colorizeStatusCode(statusCodeValue);

            return log.replace(APACHE_FORMAT_REGEX, color);

        case 'text':
            var logLevel = log.match(TEXT_FORMAT_REGEX)[0],
                colorizedLog = log.replace(logLevel, colorizeLogLevel(logLevel));

            return colorizedLog;

        case 'customleveljson':
            var levelIndex = log.match(CUSTOMLEVELJSON_REGEX).index,
                colorizedLog = colorizeLogLevel(log.substr(levelIndex + 10, 5).trim().replace(/['"]+/g, ''));

            return log.replace(CUSTOMLEVELJSON_REGEX, "level: " + '"' + colorizedLog + '"');
{'fraction_non_alphanumeric': 0.11432325886990802, 'fraction_numerical': 0.0073003358154475105, 'mean_word_length': 2.9098173515981736, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7166820', 'n_tokens_mistral': 1977, 'n_tokens_neox': 1890, 'n_words': 412}