<commit_before>"use strict";
var generateLogid = require("./logid")

var getLogid = function(){
    if (this.state.logid){
        return this.state.logid
    } else if (this.request.query.logid){
        this.state.logid = this.request.query.logid
        return this.state.logid
    } else if(this.request.query['Tc-Default-Logid']){
        this.state.logid = this.request.query['Tc-Default-Logid'];
        return this.state.logid
    }else{
        this.state.logid = generateLogid()
        return this.state.logid
    }
}

var middleware = function (logging){
    return function(config){
        var favicon_path = "/favicon.ico"
        if (config) {
            logging.configure(config)
            if (config.favicon) {
                favicon_path = config.favicon
            }
        }
        return function *(next) {
            if (favicon_path == this.path) {
                return yield next;
            }
            this.log = logging;
            var logid = getLogid.bind(this)()
            logging.request({
                "logid": logid,
                "url": this.url,
                "headers": this.headers,
            })       
            try {
                yield next;
            }
            catch (e) {
                logging.error({"message": e});
                throw e;
            }
            logging.perform({
                "logid": logid,
                "statusCode": this.status,
            })
        }
    }
}

module.exports = middleware<commit_msg>now if error.status is set and errror.status is not 5xx, do not print the error log since it is a simple NOT FOUND error<commit_after>"use strict";
var generateLogid = require("./logid")

var getLogid = function(){
    if (this.state.logid){
        return this.state.logid
    } else if (this.request.query.logid){
        this.state.logid = this.request.query.logid
        return this.state.logid
    } else if(this.request.query['Tc-Default-Logid']){
        this.state.logid = this.request.query['Tc-Default-Logid'];
        return this.state.logid
    }else{
        this.state.logid = generateLogid()
        return this.state.logid
    }
}

var middleware = function (logging){
    return function(config){
        var favicon_path = "/favicon.ico"
        if (config) {
            logging.configure(config)
            if (config.favicon) {
                favicon_path = config.favicon
            }
        }
        return function *(next) {
            if (favicon_path == this.path) {
                return yield next;
            }
            this.log = logging;
            var logid = getLogid.bind(this)()
            logging.request({
                "logid": logid,
                "url": this.url,
                "headers": this.headers,
            })       
            try {
                yield next;
            }
            catch (e) {
                if (!e.status || e.status.toString().match(/^5\d\d$/)) {
                    logging.error({"message": e});
                }
                throw e;
            }
            logging.perform({
                "logid": logid,
                "statusCode": this.status,
            })
        }
    }
}

module.exports = middleware
{'fraction_non_alphanumeric': 0.11764705882352941, 'fraction_numerical': 0.0006191950464396285, 'mean_word_length': 1.400445765230312, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 3, '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': '6371217', 'n_tokens_mistral': 940, 'n_tokens_neox': 903, 'n_words': 191}