<commit_before>var _           = require("underscore")._;
    queryString = require("querystring"),
    cache       = require("./simple-cache"),
    Registry    = require("./registry");

var createRestHandler = function(restFn, cb) {
  var handler = function(req, res, next) {
    if (req.url.indexOf('?') > -1) {
      req.query = queryString.parse(req.url.split('?')[1]);
    }

    restFn(req, res, function(err, result) {
      if (err) {
        res.statusCode = err.statusCode || 500;
        res.setHeader('Content-Type', 'text/plain');
        res.end(JSON.stringify(err));
      } else if (_.isNull(result) || _.isUndefined(result)) {
        res.writeHead(404, {'Content-Type': 'text/plain'});
        res.end(JSON.stringify("Document not found"));
      } else {
        res.writeHead(200, {'Content-Type': 'application/json'});
        res.end(JSON.stringify(result));
      }
    });
  };
  cb && cb(null, handler); // callback for async-style coding
  return handler; // nothing async here, so also return result fn.

}; // end createRestHandler

// public api
var restApi = module.exports = function(middlewareContainer) {
  this.app = middlewareContainer;
  this.routes = new Registry();
};

restApi.prototype = {
  registerRoute: function(verb, routePath, routeFn, cb) {
    var fullRoutePath = "/_rest/" + routePath.replace(/^\//, ''),
      key = verb + routePath,
      me = this;

    if (!me.routes.findById(key)) {
      me.routes.add({ id: key, verb: verb, route: routePath, fn: routeFn });
      console.trace("Registering rest path " + fullRoutePath + " for verb " + verb);
      me.app[verb](fullRoutePath, createRestHandler(routeFn));
      cb && cb(null);
    } else {<commit_msg>Added logger and changed console trace calls to logger trace.<commit_after>var _           = require("underscore")._;
    queryString = require("querystring"),
    cache       = require("./simple-cache"),
    Registry    = require("./registry");

var createRestHandler = function(restFn, cb) {
  var handler = function(req, res, next) {
    if (req.url.indexOf('?') > -1) {
      req.query = queryString.parse(req.url.split('?')[1]);
    }

    restFn(req, res, function(err, result) {
      if (err) {
        res.statusCode = err.statusCode || 500;
        res.setHeader('Content-Type', 'text/plain');
        res.end(JSON.stringify(err));
      } else if (_.isNull(result) || _.isUndefined(result)) {
        res.writeHead(404, {'Content-Type': 'text/plain'});
        res.end(JSON.stringify("Document not found"));
      } else {
        res.writeHead(200, {'Content-Type': 'application/json'});
        res.end(JSON.stringify(result));
      }
    });
  };
  cb && cb(null, handler); // callback for async-style coding
  return handler; // nothing async here, so also return result fn.

}; // end createRestHandler

// public api
var restApi = module.exports = function(middlewareContainer) {
  var me = this;
  me.app = middlewareContainer;
  me.routes = new Registry();
  me.logger = null;
  cache.getItemsWait(["feather-logger"], function(err, cacheItems) {
    me.logger = cacheItems["feather-logger"];
  });
};

restApi.prototype = {
  registerRoute: function(verb, routePath, routeFn, cb) {
    var fullRoutePath = "/_rest/" + routePath.replace(/^\//, ''),
      key = verb + routePath,
      me = this;

    if (!me.routes.findById(key)) {
      me.routes.add({ id: key, verb: verb, route: routePath, fn: routeFn });
      me.logger.trace({message: "Registering rest path " + fullRoutePath + " for verb " + verb, category: "feather.rest"});
      me.app[verb](fullRoutePath, createRestHandler(routeFn));
      cb && cb(null);
    } else {
{'fraction_non_alphanumeric': 0.16780541131456683, 'fraction_numerical': 0.006012571740912818, 'mean_word_length': 3.0043763676148796, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1911784', 'n_tokens_mistral': 1160, 'n_tokens_neox': 1138, 'n_words': 256}