<commit_before>'use strict';

const config = require('turing-config');
const winston = require('winston');
const stackTrace = require('stack-trace');
const path = require('path');
const cls = require('continuation-local-storage');
const extend = require('extend');

const transportModules = config.get('turing:logging:transports');
const transports = [];

transportModules.forEach((transportModule) => {
  try {
    let Transport;
    if (transportModule.type) {
      Transport = winston.transports[transportModule.type];
    } else if (transportModule.module) {
      Transport = require(transportModule.module);
    }
    if (Transport) {
      transports.push(new Transport(transportModule.opts));
    }
  } catch (error) {
    console.log(error);
  }
});

const logger = new winston.Logger({
  exitOnError: false,
  transports
});

function findCaller() {
  const caller = stackTrace.get()[6];

  const file = path.relative(process.cwd(), caller.getFileName());
  const line = caller.getLineNumber();
  const column = caller.getColumnNumber();

  return `${file}#${line}:${column}`;
}

// TODO: Add more information to meta?!
logger.rewriters.push((level, msg, meta) => {
  const namespace = cls.getNamespace(config.get('turing:logging:namespace'));
  const request = namespace.get('request');
  const uuid = namespace.get('uuid');
  const metaFromConf = config.get('turing:logging:meta');

  if (uuid) {
    meta.uuid = uuid;
  }

  meta.caller = findCaller();

  if (request) {
    const headers = config.get('turing:logging:headers');<commit_msg>meta is big enough<commit_after>'use strict';

const config = require('turing-config');
const winston = require('winston');
const stackTrace = require('stack-trace');
const path = require('path');
const cls = require('continuation-local-storage');
const extend = require('extend');

const transportModules = config.get('turing:logging:transports');
const transports = [];

transportModules.forEach((transportModule) => {
  try {
    let Transport;
    if (transportModule.type) {
      Transport = winston.transports[transportModule.type];
    } else if (transportModule.module) {
      Transport = require(transportModule.module);
    }
    if (Transport) {
      transports.push(new Transport(transportModule.opts));
    }
  } catch (error) {
    console.log(error);
  }
});

const logger = new winston.Logger({
  exitOnError: false,
  transports
});

function findCaller() {
  const caller = stackTrace.get()[6];

  const file = path.relative(process.cwd(), caller.getFileName());
  const line = caller.getLineNumber();
  const column = caller.getColumnNumber();

  return `${file}#${line}:${column}`;
}

logger.rewriters.push((level, msg, meta) => {
  const namespace = cls.getNamespace(config.get('turing:logging:namespace'));
  const request = namespace.get('request');
  const uuid = namespace.get('uuid');
  const metaFromConf = config.get('turing:logging:meta');

  if (uuid) {
    meta.uuid = uuid;
  }

  meta.caller = findCaller();

  if (request) {
    const headers = config.get('turing:logging:headers');
{'fraction_non_alphanumeric': 0.155873739017247, 'fraction_numerical': 0.0006508298080052066, 'mean_word_length': 4.55877034358047, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1050447', 'n_tokens_mistral': 922, 'n_tokens_neox': 925, 'n_words': 198}