<commit_before>var _ = require('underscore');
var logLevels = require('log4js').levels;

function Logger(log4js) {
  this.log4js = log4js;
}

Logger.prototype._log = function(level, message, extra) {
  var fields = _.extend({}, extra);
  if (message instanceof Error) {
    var error = message;
    message = error.message;
    fields.error = error;
  }
  this.log4js.log(level, message, fields);
};


['trace', 'debug', 'info', 'warn', 'error', 'fatal'].forEach(function(level) {
  Logger.prototype[level] = function(message, extra) {
    this._log(logLevels[level.toUpperCase()], message, extra);
  };
});

module.exports = Logger;<commit_msg>Accept Context objects as extra in Logger<commit_after>var _ = require('underscore');
var logLevels = require('log4js').levels;
var Context = require('./context');

function Logger(log4js) {
  this.log4js = log4js;
}

/**
 * @param {String} level
 * @param {String} message
 * @param {Context|Object} extra
 * @private
 */
Logger.prototype._log = function(level, message, extra) {
  if (extra instanceof Context) {
    extra = extra.toHash();
  }
  var fields = _.extend({}, extra);
  if (message instanceof Error) {
    var error = message;
    message = error.message;
    fields.error = error;
  }
  this.log4js.log(level, message, fields);
};


['trace', 'debug', 'info', 'warn', 'error', 'fatal'].forEach(function(level) {
  Logger.prototype[level] = function(message, extra) {
    this._log(logLevels[level.toUpperCase()], message, extra);
  };
});

module.exports = Logger;
{'fraction_non_alphanumeric': 0.16983606557377048, 'fraction_numerical': 0.006557377049180328, 'mean_word_length': 4.411347517730497, 'pattern_counts': {'":': 0, '<': 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': '3163542', 'n_tokens_mistral': 506, 'n_tokens_neox': 492, 'n_words': 114}