<commit_before>const util = require('util')
util.inspect.defaultOptions.maxArrayLength = null
util.inspect.defaultOptions.colors = true

const env = process.env.NODE_ENV || ''
const env2formats = {
  '': prodFormat,
  production: prodFormat,
  development: devFormat,
  standalone: devFormat,
  test: devFormat
}
const format = env2formats[env]

if (!format) console.error('Error while loading the logger')

function log (type, message, label, namespace) {
  if (type !== 'debug' || (process.env.DEBUG && process.env.DEBUG.length)) {
    console.log(format(type, message, label, namespace))
  }
}

module.exports = log

log.namespace = function (namespace) {
  return function (type, message, label, ns = namespace) {
    log(type, message, label, ns)
  }
}

function prodFormat (type, message, label, namespace) {
  return JSON.stringify({ type, message, label, namespace })
}

function devFormat (type, message, label, namespace) {
  let formatmessage = message
  if (typeof formatmessage !== 'string') {
    formatmessage = util.inspect(formatmessage)
  }

  let formatlabel = ` : "${label}" `
  if (label === undefined) formatlabel = ``

  let formatnamespace = `\u001b[35m${namespace}: \u001b[0m`
  if (namespace === undefined) formatnamespace = ``

  const type2color = {
    debug: 6,   // cyan
    warning: 3, // yellow
    info: 4,    // blue
    error: 1,   // red
    ok: 2       // green
  }

  let formattype = type
  if (type2color[type]) {
    formattype = `\u001b[3${type2color[type]}m${type}\u001b[0m`
  }
  return `${formatnamespace}${formattype}${formatlabel} : ${formatmessage}`
}<commit_msg>feat: add time in production logs<commit_after>const util = require('util')
util.inspect.defaultOptions.maxArrayLength = null
util.inspect.defaultOptions.colors = true

const env = process.env.NODE_ENV || ''
const env2formats = {
  '': prodFormat,
  production: prodFormat,
  development: devFormat,
  standalone: devFormat,
  test: devFormat
}
const format = env2formats[env]

if (!format) console.error('Error while loading the logger')

function log (type, message, label, namespace) {
  if (type !== 'debug' || (process.env.DEBUG && process.env.DEBUG.length)) {
    console.log(format(type, message, label, namespace))
  }
}

module.exports = log

log.namespace = function (namespace) {
  return function (type, message, label, ns = namespace) {
    log(type, message, label, ns)
  }
}

function prodFormat (type, message, label, namespace) {
  return JSON.stringify({ time: new Date(), type, message, label, namespace })
}

function devFormat (type, message, label, namespace) {
  let formatmessage = message
  if (typeof formatmessage !== 'string') {
    formatmessage = util.inspect(formatmessage)
  }

  let formatlabel = ` : "${label}" `
  if (label === undefined) formatlabel = ``

  let formatnamespace = `\u001b[35m${namespace}: \u001b[0m`
  if (namespace === undefined) formatnamespace = ``

  const type2color = {
    debug: 6,   // cyan
    warning: 3, // yellow
    info: 4,    // blue
    error: 1,   // red
    ok: 2       // green
  }

  let formattype = type
  if (type2color[type]) {
    formattype = `\u001b[3${type2color[type]}m${type}\u001b[0m`
  }
  return `${formatnamespace}${formattype}${formatlabel} : ${formatmessage}`
}
{'fraction_non_alphanumeric': 0.14561618638871857, 'fraction_numerical': 0.01655426118945432, 'mean_word_length': 3.906766917293233, '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': '5236390', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1032, 'n_words': 270}