Introduce debug instead of console.log

This commit is contained in:
Gaël Métais
2014-11-28 17:53:39 +01:00
parent 2a316ebb1e
commit 6089e5fe20
5 changed files with 31 additions and 17 deletions
+4 -4
View File
@@ -1,6 +1,6 @@
#!/usr/bin/env node
//var color = require('colors');
var debug = require('debug')('ylt:cli');
var YellowLabTools = require('../lib/yellowlabtools');
@@ -17,17 +17,17 @@ var url = process.argv[2];
'use strict';
var ylt = new YellowLabTools(url);
console.log('Test launched...');
debug('Test launched...');
ylt.
then(function(data) {
console.log('Success');
debug('Success');
console.log(JSON.stringify(data, null, 2));
}).fail(function(err) {
console.error('Test failed for %s', url);
debug('Test failed for %s', url);
console.error(err);
});
+10
View File
@@ -1,4 +1,5 @@
var Q = require('q');
var debug = require('debug')('ylt:ruleschecker');
var RulesChecker = function() {
'use strict';
@@ -8,6 +9,8 @@ var RulesChecker = function() {
var results = {};
var err = null;
debug('Starting checking rules');
for (var metricName in policies) {
var policy = policies[metricName];
@@ -38,9 +41,16 @@ var RulesChecker = function() {
rule.abnormalityScore = Math.min(Math.round(abnormalityScore), 0);
results[metricName] = rule;
} else {
debug('Metric %s not found for tool %s', metricName, policy.tool);
}
}
debug('Rules checking finished');
return results;
};
};
+3 -2
View File
@@ -1,4 +1,5 @@
var Q = require('q');
var debug = require('debug')('ylt:yellowlabtools');
var phantomasWrapper = require('./tools/phantomasWrapper');
var rulesChecker = require('./rulesChecker');
@@ -29,8 +30,8 @@ var Runner = function(params) {
deferred.resolve(data);
}).fail(function(err) {
console.log('Run failed');
console.log(err);
debug('Run failed');
debug(err);
deferred.reject(err);
});
+9 -7
View File
@@ -1,7 +1,9 @@
var async = require('async');
var Q = require('q');
var debug = require('debug')('ylt:phantomaswrapper');
var phantomas = require('phantomas');
var PhantomasWrapper = function() {
'use strict';
@@ -47,16 +49,16 @@ var PhantomasWrapper = function() {
};
// Output the command line for debugging purpose
console.log('If you want to reproduce the phantomas task only, copy the following command line:');
debug('If you want to reproduce the phantomas task only, copy the following command line:');
var optionsString = '';
for (var opt in options) {
optionsString += ' ' + '--' + opt + '=' + options[opt];
}
console.log('node node_modules/phantomas/bin/phantomas.js --url=' + task.url + optionsString + ' --verbose');
debug('node node_modules/phantomas/bin/phantomas.js --url=' + task.url + optionsString + ' --verbose');
// Kill the application if nothing happens for 10 minutes
var killer = setTimeout(function() {
console.log('Killing the app because the test on ' + task.url + ' was launched 10 minutes ago');
debug('Killing the app because the test on ' + task.url + ' was launched 10 minutes ago');
// If in server mode, forever will restart the server
process.exit(1);
}, 600000);
@@ -66,7 +68,7 @@ var PhantomasWrapper = function() {
async.retry(triesNumber, function(cb) {
phantomas(task.url, options, function(err, json, results) {
console.log('Returning from Phantomas');
debug('Returning from Phantomas');
// Adding some YellowLabTools errors here
if (json && json.metrics && !json.metrics.javascriptExecutionTree) {
@@ -79,12 +81,12 @@ var PhantomasWrapper = function() {
// Don't cancel test if it is a timeout and we've got some results
if (err === 252 && json) {
console.log('Timeout after ' + options.timeout + ' seconds. But it\'s not a problem, the test is valid.');
debug('Timeout after ' + options.timeout + ' seconds. But it\'s not a problem, the test is valid.');
err = null;
}
if (err) {
console.log('Attempt failed. Error code ' + err);
debug('Attempt failed. Error code ' + err);
}
cb(err, json);
@@ -94,7 +96,7 @@ var PhantomasWrapper = function() {
clearTimeout(killer);
if (err) {
console.log('All ' + triesNumber + ' attemps failed for the test');
debug('All ' + triesNumber + ' attemps failed for the test');
deferred.reject(err);
} else {
+5 -4
View File
@@ -10,12 +10,13 @@
},
"main": "./lib/yellowlabtools.js",
"dependencies": {
"phantomas": "1.7.0",
"express": "~4.10.1",
"async": "~0.9.0",
"socket.io": "~1.2.0",
"body-parser": "~1.9.2",
"compression": "~1.2.0"
"compression": "~1.2.0",
"debug": "^2.1.0",
"express": "~4.10.1",
"phantomas": "1.7.0",
"socket.io": "~1.2.0"
},
"devDependencies": {
"chai": "^1.9.2",