<commit_before>"use strict"

/*jshint esversion: 6 */

/*
* Here goes privates functions and variables
*/
const privates = {

  print: function(content, color = "", level = false, options) {

    var self = this;
    var list = [];
    var item;
    var mainColor = self.colors.reset;

    while(item = this.interpolation.regexp.exec(content)) {
      max--;
      if(max <= 0) { break }
      list.push(item);
    }

    content = {
      colored: content,
      unformatted: content
    };

    if(options.formatColors) {
      color = options.formatColors;
    }

    for(let c of color.split(".")) {
      mainColor = (typeof self.colors[c] !== typeof undefined) ? `${mainColor}${self.colors[c]}` : mainColor;
    }

    var max = 200;

    var elaborate = function(content, item) {

      let element = item[1].split(self.interpolation.separator);

      element = {
        colors: (element.length > 1) ? element[0] : "",
        phrase: (element.length > 1) ? element[1] : element[0]
      }

      let result = { unformatted: content.unformatted.replace(`${item[0]}`, `${element.phrase}`) }

      for(let color of element.colors.split(".")) {
        element.phrase = (typeof self.colors[color] !== typeof undefined) ? `${self.colors[color]}${element.phrase}` : element.phrase;
      }
      result.colored = content.colored.replace(`${item[0]}`, `${element.phrase}${mainColor}`);

      return result;

    }
    for(item of list) {
      content = elaborate(content, item);
    }
    if(options.fabulous) {
      content.colored = privates.fabulous.call(self, content.unformatted);
    }

    content.formatted = self.formatText;

    let result =  {
      content: content.colored,
      level: level,
      date: new Date(),
      pid: process.pid
    };
    for(let formatAction in self.formatActions) {

      if(self.formatText.includes(formatAction)) {

        let s = self.formatActions[formatAction](result);
        let re = new RegExp(`%${formatAction}`, 'g');
        content.formatted = content.formatted.replace(re, s);

      }

    }

    content.formatted = `${mainColor}${content.formatted}${self.colors.reset}`;
    delete content.colored;

    this.logFunction(content.formatted);

    result.content = content;

    return result;

  },
  _say: require(`${__dirname}/say.js`),
  _fs: require('fs'),
  say: function(text, queue, force = false) {

    var self = this;

    if(!queue.length || force) {

      if(!force) {
        queue.push(text);
      }
      this._say.speak(text, 1.2, function(err) {
        if (err){
          return console.error(err);
        }
        queue.shift();
        if(!!queue.length) {
          self.say(queue[0], queue, true);
        }
      });

    } else if(!force) {
      queue.push(text);
    }

  },
  fabulous: function(content) {

    var result = "";
    var mainColor = this.colors.reset;
    var exitSafe = content.length;
    var counter = 0;

    for(let i = 0; i <= content.length - 1; i++) {

      if(counter > exitSafe) {
        console.warn("fabulous has something wrong, exit");
        break;
      }

      let color = "";

      if(content[i] == " ") {

        let c1 = content.slice(0, i);
        let c2 = content.slice(i, content.length).replace(" ", "");
        i--;
        content = c1+c2;
        result += " ";

      } else {

        for(let c of this.fabulizer[i%this.fabulizer.length].split(".")) {
          color += this.colors[c];
        }
        result += `${color}${content[i]}`;

      }
      counter++;

    }

    return `${this.colors.reset}${result}`;

  },
  setupHandlers: function(handlers) {

    if(typeof handlers === typeof undefined) {
      return false;
    }

    for(let name in handlers) {
      let fn = this.handlers[name].constructor(handlers[name].logAs || undefined, handlers[name].exitCode)
      process.on(name, fn);
    }

    return true;

  },
  writeFile: function(level, content) {
    privates._fs.appendFileSync(`${this.fileLog.path}/${level}.log`, `${content}\n`);
  }

};

/*
* Logger function
*/
class Logger {

  constructor (options = {
    level: "debug",
    formatColors: {},
    labels: {},
    formatText: "%content",
    logFunction: console.warn,
    fileLog: {
      path: ".",
      rank: {
        info: false,
        debug: false,
        error: false,
        warning: false
      }
    },
    fabulous: {
      formatColors: []
    }
  }) {

    var self = this;

    this.colors = {<commit_msg>changed default text for formatText<commit_after>"use strict"

/*jshint esversion: 6 */

/*
* Here goes privates functions and variables
*/
const privates = {

  print: function(content, color = "", level = false, options) {

    var self = this;
    var list = [];
    var item;
    var mainColor = self.colors.reset;

    while(item = this.interpolation.regexp.exec(content)) {
      max--;
      if(max <= 0) { break }
      list.push(item);
    }

    content = {
      colored: content,
      unformatted: content
    };

    if(options.formatColors) {
      color = options.formatColors;
    }

    for(let c of color.split(".")) {
      mainColor = (typeof self.colors[c] !== typeof undefined) ? `${mainColor}${self.colors[c]}` : mainColor;
    }

    var max = 200;

    var elaborate = function(content, item) {

      let element = item[1].split(self.interpolation.separator);

      element = {
        colors: (element.length > 1) ? element[0] : "",
        phrase: (element.length > 1) ? element[1] : element[0]
      }

      let result = { unformatted: content.unformatted.replace(`${item[0]}`, `${element.phrase}`) }

      for(let color of element.colors.split(".")) {
        element.phrase = (typeof self.colors[color] !== typeof undefined) ? `${self.colors[color]}${element.phrase}` : element.phrase;
      }
      result.colored = content.colored.replace(`${item[0]}`, `${element.phrase}${mainColor}`);

      return result;

    }
    for(item of list) {
      content = elaborate(content, item);
    }
    if(options.fabulous) {
      content.colored = privates.fabulous.call(self, content.unformatted);
    }

    self.formatText = (typeof self.formatText === typeof "string") ? self.formatText : "%levelLabel %pidLabel %date - %content";
    content.formatted = self.formatText;

    let result =  {
      content: content.colored,
      level: level,
      date: new Date(),
      pid: process.pid
    };
    for(let formatAction in self.formatActions) {

      if(self.formatText.includes(formatAction)) {

        let s = self.formatActions[formatAction](result);
        let re = new RegExp(`%${formatAction}`, 'g');
        content.formatted = content.formatted.replace(re, s);

      }

    }

    content.formatted = `${mainColor}${content.formatted}${self.colors.reset}`;
    delete content.colored;

    this.logFunction(content.formatted);

    result.content = content;

    return result;

  },
  _say: require(`${__dirname}/say.js`),
  _fs: require('fs'),
  say: function(text, queue, force = false) {

    var self = this;

    if(!queue.length || force) {

      if(!force) {
        queue.push(text);
      }
      this._say.speak(text, 1.2, function(err) {
        if (err){
          return console.error(err);
        }
        queue.shift();
        if(!!queue.length) {
          self.say(queue[0], queue, true);
        }
      });

    } else if(!force) {
      queue.push(text);
    }

  },
  fabulous: function(content) {

    var result = "";
    var mainColor = this.colors.reset;
    var exitSafe = content.length;
    var counter = 0;

    for(let i = 0; i <= content.length - 1; i++) {

      if(counter > exitSafe) {
        console.warn("fabulous has something wrong, exit");
        break;
      }

      let color = "";

      if(content[i] == " ") {

        let c1 = content.slice(0, i);
        let c2 = content.slice(i, content.length).replace(" ", "");
        i--;
        content = c1+c2;
        result += " ";

      } else {

        for(let c of this.fabulizer[i%this.fabulizer.length].split(".")) {
          color += this.colors[c];
        }
        result += `${color}${content[i]}`;

      }
      counter++;

    }

    return `${this.colors.reset}${result}`;

  },
  setupHandlers: function(handlers) {

    if(typeof handlers === typeof undefined) {
      return false;
    }

    for(let name in handlers) {
      let fn = this.handlers[name].constructor(handlers[name].logAs || undefined, handlers[name].exitCode)
      process.on(name, fn);
    }

    return true;

  },
  writeFile: function(level, content) {
    privates._fs.appendFileSync(`${this.fileLog.path}/${level}.log`, `${content}\n`);
  }

};

/*
* Logger function
*/
class Logger {

  constructor (options = {
    level: "debug",
    formatColors: {},
    labels: {},
    formatText: "%levelLabel %pidLabel %date - %content",
    logFunction: console.warn,
    fileLog: {
      path: ".",
      rank: {
        info: false,
        debug: false,
        error: false,
        warning: false
      }
    },
    fabulous: {
      formatColors: []
    }
  }) {

    var self = this;

    this.colors = {
{'fraction_non_alphanumeric': 0.1606456571867794, 'fraction_numerical': 0.005270670912484902, 'mean_word_length': 2.3107960741548528, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '7343054', 'n_tokens_mistral': 2961, 'n_tokens_neox': 2870, 'n_words': 591}