hey we got a log

This commit is contained in:
soulgalore 2016-04-14 10:43:54 +02:00
parent e0e9b27382
commit f8903bd34d
4 changed files with 46 additions and 2 deletions

View File

@ -7,6 +7,8 @@ const cli = require('../lib/support/cli'),
App = require('../lib/app'),
Promise = require('bluebird'),
difference = require('lodash.difference'),
logging = require('../lib/support/logging'),
log = require('intel'),
merge = require('lodash.merge'),
loader = require('../lib/support/pluginLoader');
@ -23,6 +25,12 @@ function allInArray(sampleArray, referenceArray) {
process.exitCode = 1;
let parsed = cli.parseCommandLine();
logging.configure(parsed.options);
if (log.isEnabledFor(log.CRITICAL)) { // TODO change the threshold to VERBOSE before releasing 4.0
Promise.longStackTraces();
}
loader.parsePluginNames(parsed.raw)
.then((pluginNames) => {
@ -43,10 +51,10 @@ loader.parsePluginNames(parsed.raw)
})
.then(() => {
process.exitCode = 0;
console.log('DONE!');
log.info('Finished analysing ' + parsed.url);
})
.catch((e) => {
process.exitCode = 1;
console.error('FAIL! ' + e.message);
log.error('Failing: ' + e.message);
})
.finally(() => process.exit());

View File

@ -3,6 +3,7 @@
var fs = require('fs'),
merge = require('lodash.merge'),
Promise = require('bluebird'),
log = require('intel'),
WebPageTest = require('webpagetest');
Promise.promisifyAll(fs);
@ -29,9 +30,11 @@ module.exports = {
const wptClient = new WebPageTest(wptOptions.host, wptOptions.key);
wptOptions.firstViewOnly = !wptOptions.includeRepeatView;
log.debug('Sending url ' + url + ' to test on ' + wptOptions.host);
return wptClient.runTestAsync(url, wptOptions)
.then(function(data) {
var id = data.data.id;
log.debug('Got ' + url + ' analysed from ' + wptOptions.host);
return wptClient.getHARDataAsync(id, {})
.then((har) => {

32
lib/support/logging.js Normal file
View File

@ -0,0 +1,32 @@
'use strict';
let log = require('intel');
module.exports.configure = function configure(options) {
options = options || {};
let level = log.INFO;
switch (options.verbose) {
case 1:
level = log.DEBUG;
break;
case 2:
level = log.VERBOSE;
break;
case 3:
level = log.TRACE;
break;
default:
break;
}
if (options.silent) {
level = log.NONE;
}
log.basicConfig({
'format': '[%(date)s] %(message)s',
'level': level
});
};

View File

@ -64,6 +64,7 @@
"gpagespeed": "3.0.0",
"gridly": "1.4.1",
"influx": "4.1.0",
"intel": "1.1.0",
"jade": "1.11.0",
"line-reader": "0.4.0",
"lodash.clonedeep": "4.3.2",