<commit_before>'use strict';

let cli   = require('heroku-cli-util');
let https = require('https');
let liner = require('../lib/line_transform');

const COLORS = [
  s => cli.color.cyan(s),
  s => cli.color.magenta(s),
  s => cli.color.yellow(s),
  s => cli.color.green(s),
  s => cli.color.red(s),
  s => cli.color.blue(s),
  s => cli.color.bold.cyan(s),
  s => cli.color.bold.magenta(s),
  s => cli.color.bold.yellow(s),
  s => cli.color.bold.green(s),
  s => cli.color.bold.red(s),
  s => cli.color.bold.blue(s),
];
let assignedColors = {};
function getColorForIdentifier (i) {
  if (assignedColors[i]) return assignedColors[i];
  assignedColors[i] = COLORS[Object.keys(assignedColors).length % COLORS.length];
  return assignedColors[i];
}

let lineRegex = /^(.*?\[([\w-]+)([\d\.]+)?\]:)(.*)?$/;
function colorize (line) {
  let parsed = line.match(lineRegex);
  if (!parsed) return line;
  let header     = parsed[1];
  let identifier = parsed[2];
  let body       = parsed[4];
  return getColorForIdentifier(identifier)(header) + body;
}

function readLogs (logplexURL) {
  return new Promise(function (fulfill, reject) {
    https.get(logplexURL, function (res) {
      if (res.statusCode !== 200) cli.warn(`Expected logplex response to be 200, got ${res.statusCode}`);
      res.setEncoding('utf8');
      liner.setEncoding('utf8');
      res.pipe(liner);
      liner.on('data', line => cli.log(colorize(line)));
      res.on('close', fulfill);
    })
    .on('error', reject);
  });
}

function logDisplayer (heroku, options) {
  return heroku.request({
    path: `/apps/${options.app}/log-sessions`,
    method: 'POST',
    body: {
      tail:   options.tail,
      dyno:   options.dyno,
      source: options.source,
      lines:  options.lines,
    }
  })
  .then(response => readLogs(response.logplex_url));
}

module.exports = logDisplayer;<commit_msg>switch to got<commit_after>'use strict';

let cli   = require('heroku-cli-util');
let liner = require('../lib/line_transform');

const COLORS = [
  s => cli.color.cyan(s),
  s => cli.color.magenta(s),
  s => cli.color.yellow(s),
  s => cli.color.green(s),
  s => cli.color.red(s),
  s => cli.color.blue(s),
  s => cli.color.bold.cyan(s),
  s => cli.color.bold.magenta(s),
  s => cli.color.bold.yellow(s),
  s => cli.color.bold.green(s),
  s => cli.color.bold.red(s),
  s => cli.color.bold.blue(s),
];
let assignedColors = {};
function getColorForIdentifier (i) {
  if (assignedColors[i]) return assignedColors[i];
  assignedColors[i] = COLORS[Object.keys(assignedColors).length % COLORS.length];
  return assignedColors[i];
}

let lineRegex = /^(.*?\[([\w-]+)([\d\.]+)?\]:)(.*)?$/;
function colorize (line) {
  let parsed = line.match(lineRegex);
  if (!parsed) return line;
  let header     = parsed[1];
  let identifier = parsed[2];
  let body       = parsed[4];
  return getColorForIdentifier(identifier)(header) + body;
}

function readLogs (logplexURL) {
  return new Promise(function (fulfill, reject) {
    let res = cli.got.stream(logplexURL);
    res.setEncoding('utf8');
    liner.setEncoding('utf8');
    res.pipe(liner);
    liner.on('data', line => cli.log(colorize(line)));
    res.on('close', fulfill);
    res.on('error', reject);
  });
}

function logDisplayer (heroku, options) {
  return heroku.request({
    path: `/apps/${options.app}/log-sessions`,
    method: 'POST',
    body: {
      tail:   options.tail,
      dyno:   options.dyno,
      source: options.source,
      lines:  options.lines,
    }
  })
  .then(response => readLogs(response.logplex_url));
}

module.exports = logDisplayer;
{'fraction_non_alphanumeric': 0.1918458531136554, 'fraction_numerical': 0.004468025691147724, 'mean_word_length': 3.5113350125944582, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '470629', 'n_tokens_mistral': 1332, 'n_tokens_neox': 1331, 'n_words': 249}