<commit_before>#!/usr/bin/env node

var program = require('commander')

program
  .version('0.1.0')
  .parse(process.argv)

parseURL = program.args[0];

try {
    var Spooky = require('spooky');
} catch (e) {
    var Spooky = require('../lib/spooky');
}

var spooky = new Spooky({
  child: {
    transport: 'http'
  },
  casper: {
    logLevel: 'debug',
    verbose: true
  }
}, function (err) {
  if (err) {
    e = new Error('Failed to initialize SpookyJS');
    e.details = err;
    throw e;
  }

  spooky.start(parseURL);
  spooky.then(function () {
    this.emit('hello', 'Hello, from ' + this.evaluate(function () {
      return document.title;
    }));
  });
  spooky.run();
});

spooky.on('error', function (e, stack) {
  console.error(e);

  if (stack) {
    console.log(stack);
  }
});

spooky.on('hello', function (greeting) {
  console.log(greeting);
});

spooky.on('log', function (log) {
  if (log.space === 'remote') {
    console.log(log.message.replace(/ \- .*/, ''));
  }
});<commit_msg>Logging errors & displaying stack, logging messages<commit_after>#!/usr/bin/env node

var program = require('commander');
var util = require('util');

program
  .version('0.1.0')
  .parse(process.argv)

parseURL = program.args[0];

try {
    var Spooky = require('spooky');
} catch (e) {
    var Spooky = require('../lib/spooky');
}

var spooky = new Spooky({
  child: {
    transport: 'http'
  },
  casper: {
    logLevel: 'debug',
    verbose: true
  }
}, function (err) {
  if (err) {
    e = new Error('Failed to initialize SpookyJS');
    e.details = err;
    throw e;
  }

  spooky.start(parseURL);
    spooky.run();
});

spooky.on('page.error', function (e, stack) {
  console.error('Page error: ' + e);

  if (stack) {
    console.log(util.inspect(stack, {showHidden: false, depth: null}));
  }
});

spooky.on('remote.message', function (msg) {
  console.log('Console message: ' + msg);
});
{'fraction_non_alphanumeric': 0.19442984760903836, 'fraction_numerical': 0.004203888596952181, 'mean_word_length': 3.1846153846153844, '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': '1574952', 'n_tokens_mistral': 729, 'n_tokens_neox': 720, 'n_words': 148}