<commit_before>/* Copyright © 2016-2019 <NAME> and other contributors, MIT License. */
'use strict'

// NOTES
// Valid log level values range from 100 to 999 inclusive only.

const Util = require('util')

const Print = require('./print')
const Common = require('./common')

const default_logspec = {
  level: 'info',
  default_level: 'debug',
  level_text: {
    100: 'all',
    200: 'debug',
    300: 'info',
    400: 'warn',
    500: 'error',
    600: 'fatal',
    999: 'none'
  },
  logger: json_logger
}

const level_abbrev = {
  quiet: 'none',
  silent: 'none',
  any: 'all',
  all: 'all',
  print: 'debug',
  standard: 'info',
  test: 'warn'
}

const internal_loggers = {
  flat_logger,
  test_logger,
  json_logger
}

function make_logging() {
  const logging = {
    default_logspec: Common.deep(default_logspec),
    level_abbrev: Common.deep(level_abbrev),
    load_logger,
    build_log_spec,
    build_log,
    flat_logger,
    test_logger,
    json_logger
  }
  return logging
}

module.exports = make_logging

function flat_logger(entry) {
  var level_str = (entry.level_name+'').toUpperCase()
  if (level_str.length < 5) {
    level_str += '_'.repeat(5 - level_str.length)
  }
  level_str = level_str.substring(0, 5)

  var ds =
    null != entry.err
      ? [entry.err.message, entry.err.callpoint]
      : null != entry.res
      ? [entry.res]
      : null != entry.msg
      ? [entry.msg]
      : Array.isArray(entry.data)
      ? entry.data
      : null != entry.data
      ? [entry.data]
      : []

  var da = new Array(ds.length)
  for (var i = 0; i < ds.length; i++) {
    da[i] = 'object' === typeof ds[i] ? Common.clean(ds[i]) : ds[i]
    da[i] = Util.inspect(da[i], {
      compact: true,
      depth: entry.depth$ || 3,
      breakLength: Infinity
    })
  }

  var data_str = ds.join(' ')

  var plugin_str =
    null == entry.plugin_name
      ? ''
      : entry.plugin_name +
        (null == entry.plugin_tag || '-' == entry.plugin_tag
          ? ''
          : '$' + entry.plugin_tag)

  var sb = [
    entry.isot,
    'string' === typeof(entry.seneca_id) ? entry.seneca_id.substring(0,5) : '-----',
    level_str,
    null == entry.kind ? 'log' : entry.kind,
    null == entry.case ? 'LOG' : entry.case,
    plugin_str,
    null == entry.pattern ? '' : entry.pattern,
    null == entry.action ? '' : entry.action,
    null == entry.idpath ? '' : entry.idpath,<commit_msg>fix log data corruption 3<commit_after>/* Copyright © 2016-2019 <NAME> and other contributors, MIT License. */
'use strict'

// NOTES
// Valid log level values range from 100 to 999 inclusive only.

const Util = require('util')

const Print = require('./print')
const Common = require('./common')

const default_logspec = {
  level: 'info',
  default_level: 'debug',
  level_text: {
    100: 'all',
    200: 'debug',
    300: 'info',
    400: 'warn',
    500: 'error',
    600: 'fatal',
    999: 'none'
  },
  logger: json_logger
}

const level_abbrev = {
  quiet: 'none',
  silent: 'none',
  any: 'all',
  all: 'all',
  print: 'debug',
  standard: 'info',
  test: 'warn'
}

const internal_loggers = {
  flat_logger,
  test_logger,
  json_logger
}

function make_logging() {
  const logging = {
    default_logspec: Common.deep(default_logspec),
    level_abbrev: Common.deep(level_abbrev),
    load_logger,
    build_log_spec,
    build_log,
    flat_logger,
    test_logger,
    json_logger
  }
  return logging
}

module.exports = make_logging

function flat_logger(entry) {
  var level_str = (entry.level_name+'').toUpperCase()
  if (level_str.length < 5) {
    level_str += '_'.repeat(5 - level_str.length)
  }
  level_str = level_str.substring(0, 5)

  var data_src =
    null != entry.err
      ? [entry.err.message, entry.err.callpoint]
      : null != entry.res
      ? [entry.res]
      : null != entry.msg
      ? [entry.msg]
      : Array.isArray(entry.data)
      ? entry.data
      : null != entry.data
      ? [entry.data]
      : []

  var data_fmt = new Array(data_src.length)
  for (var i = 0; i < data_src.length; i++) {
    data_fmt[i] =
      'object' === typeof data_src[i] ?
      Common.clean(data_src[i]) :
      data_src[i]
    data_fmt[i] = Util.inspect(data_fmt[i], {
      compact: true,
      depth: entry.depth$ || 3,
      breakLength: Infinity
    })
  }

  var data_str = data_fmt.join(' ')

  var plugin_str =
    null == entry.plugin_name
      ? ''
      : entry.plugin_name +
        (null == entry.plugin_tag || '-' == entry.plugin_tag
          ? ''
          : '$' + entry.plugin_tag)

  var sb = [
    entry.isot,
    'string' === typeof(entry.seneca_id) ? entry.seneca_id.substring(0,5) : '-----',
    level_str,
    null == entry.kind ? 'log' : entry.kind,
    null == entry.case ? 'LOG' : entry.case,
    plugin_str,
    null == entry.pattern ? '' : entry.pattern,
    null == entry.action ? '' : entry.action,
    null == entry.idpath ? '' : entry.idpath,
{'fraction_non_alphanumeric': 0.15735833673053404, 'fraction_numerical': 0.017733387688544638, 'mean_word_length': 2.6160648489314666, 'pattern_counts': {'":': 0, '<': 9, '<?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': '4351646', 'n_tokens_mistral': 1816, 'n_tokens_neox': 1740, 'n_words': 381}