<commit_before>var humanize = require('humanize-number');
var bytes = require('bytes');

module.exports = prod_logger;

function prod_logger() {
    return function *logger(next) {
        // request
        var start = new Date;
        var asset = this.originalUrl.indexOf('/assets/') === 0
            || this.originalUrl.indexOf('/images/') === 0
            || this.originalUrl.indexOf('/favicon.ico') === 0;
        if (!asset)
            console.log('  <-- ' + this.method + ' ' + this.originalUrl + ' ' + (this.session.uid || ''));
        try {
            yield next;
        } catch (err) {
            log(this, start, null, err, false);
            throw err;
        }
        var length = this.response.length;
        log(this, start, length, null, asset);
    }
}

function log(ctx, start, len, err, asset) {
    var status = err
        ? (err.status || 500)
        : (ctx.status || 404);

    var length;
    if (~[204, 205, 304].indexOf(status)) {
        length = '';
    } else if (null == len) {
        length = '-';
    } else {
        length = bytes(len);
    }

    var upstream = err ? 'xxx' : '-->';

    if (!asset || err || ctx.status > 400) console.log('  ' + upstream + ' %s %s %s %s %s %s',
        ctx.method,
        ctx.originalUrl,
        status,
        time(start),
        length,
        ctx.session.uid || '');<commit_msg>Send http.status.code to metrics server<commit_after>var humanize = require('humanize-number');
var bytes = require('bytes');
var nodeStats require('node-statsd');

const stats = new nodeStats();

module.exports = prod_logger;

function prod_logger() {
    return function *logger(next) {
        // request
        var start = new Date;
        var asset = this.originalUrl.indexOf('/assets/') === 0
            || this.originalUrl.indexOf('/images/') === 0
            || this.originalUrl.indexOf('/favicon.ico') === 0;
        if (!asset)
            console.log('  <-- ' + this.method + ' ' + this.originalUrl + ' ' + (this.session.uid || ''));
        try {
            yield next;
        } catch (err) {
            log(this, start, null, err, false);
            throw err;
        }
        var length = this.response.length;
        log(this, start, length, null, asset);
    }
}

function log(ctx, start, len, err, asset) {
    var status = err
        ? (err.status || 500)
        : (ctx.status || 404);

    var length;
    if (~[204, 205, 304].indexOf(status)) {
        length = '';
    } else if (null == len) {
        length = '-';
    } else {
        length = bytes(len);
    }

    var upstream = err ? 'xxx' : '-->';

    if (!asset || err || ctx.status > 400) console.log('  ' + upstream + ' %s %s %s %s %s %s',
        ctx.method,
        ctx.originalUrl,
        status,
        time(start),
        length,
        ctx.session.uid || '');

    stats.increment('http.code.' + status);
{'fraction_non_alphanumeric': 0.17054532823897187, 'fraction_numerical': 0.014588398749565822, 'mean_word_length': 1.8973843058350102, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4587234', 'n_tokens_mistral': 930, 'n_tokens_neox': 876, 'n_words': 219}