<commit_before>/** Middleware server
*
*  @copyright  Copyright (C) 2015 by Yieme
*  @module     middle-server
 */
'use strict';
var fs = require('fs')
var express     = require('express')
var app         = express()
var port        = process.env.port || 3000
var path        = require('path')
var pkgPath     = path.normalize(process.cwd() + '/package.json')
var pack        = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
var logger      = {
  info:  function(msg) { console.log('info:', msg) },
  debug: function(msg) { console.log('debug:', msg) },
  warn:  function(msg) { console.warn('warn:', msg) },
  error: function(msg) { console.error('error:', msg) },
  log:   console.log,
}

function middleServer(options) {
  if ('function' === typeof options) options = { middleware: options }
  options                    = options || {}
  if (options.logger) logger = options.logger
  if (options.port)   port   = options.port

  function consoleLog(req, res, next) {
    logger.info(req.url)
    next()
  }

  function ignoreFavicon(req, res, next) {
    if (req.url == '/favicon.ico') return res.status(404) // ignore favicon
    next()
  }

  options.pre        = options.pre        || []
  if (options.pre.length == 0) {
    options.pre.push(consoleLog)
    options.pre.push(ignoreFavicon)
  }
  options.middleware = options.middleware || require('readme-middleware')
  options.post       = options.post       || []

  for (var i=0, len = options.pre.length; i < len; i++) {
    app.use(options.pre[i])
  }

  app.use(options.middleware)
  for (i=0, len = options.post.length; i < len; i++) {
    app.use(options.post[i])
  }
  var appName = pack.name + '@' + pack.version

  app.listen(port)<commit_msg>attach logger<commit_after>/** Middleware server
*
*  @copyright  Copyright (C) 2015 by Yieme
*  @module     middle-server
 */
'use strict';
var fs = require('fs')
var express     = require('express')
var app         = express()
var port        = process.env.port || 3000
var path        = require('path')
var pkgPath     = path.normalize(process.cwd() + '/package.json')
var pack        = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
var logger      = {
  info:  function(msg) { console.log('info:', msg) },
  debug: function(msg) { console.log('debug:', msg) },
  warn:  function(msg) { console.warn('warn:', msg) },
  error: function(msg) { console.error('error:', msg) },
  log:   console.log,
}

function middleServer(options) {
  if ('function' === typeof options) options = { middleware: options }
  options                    = options || {}
  if (options.logger) logger = options.logger
  if (options.port)   port   = options.port

  function consoleLog(req, res, next) {
    req.app.locals._log.info(req.url)
    next()
  }

  function ignoreFavicon(req, res, next) {
    if (req.url == '/favicon.ico') return res.status(404) // ignore favicon
    next()
  }

  options.pre        = options.pre        || []
  if (options.pre.length == 0) {
    options.pre.push(consoleLog)
    options.pre.push(ignoreFavicon)
  }
  options.middleware = options.middleware || require('readme-middleware')
  options.post       = options.post       || []

  for (var i=0, len = options.pre.length; i < len; i++) {
    app.use(options.pre[i])
  }

  app.use(options.middleware)
  for (i=0, len = options.post.length; i < len; i++) {
    app.use(options.post[i])
  }
  var appName = pack.name + '@' + pack.version

  app.locals._log = logger
  app.listen(port)
{'fraction_non_alphanumeric': 0.16367842683632158, 'fraction_numerical': 0.008675534991324466, 'mean_word_length': 2.904063205417607, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3324784', 'n_tokens_mistral': 1191, 'n_tokens_neox': 1151, 'n_words': 260}