tooltwist
Version:
Tooltwist Command Line Interface
106 lines (93 loc) • 2.77 kB
JavaScript
exports.QUIET = 0;
exports.DEFAULT = 1;
exports.INFO = 2;
exports.DEBUG = 3;
var _level = exports.DEFAULT;
exports.setLevel = function(level) {
//console.log("Setting debug log level to " + level)
_level = level;
}
exports.getLevel = function() {
return _level;
}
/**
* Display a simple message, irrespective of the logging level.
*/
exports.always = function() { // Variable arguments
if (_level >= exports.DEBUG) {
process.stdout.write("node : ");
}
console.log.apply(console, arguments)
}
/**
* Display message, except in quiet mode.
*/
exports.log = function() { // Variable arguments
if (_level >= exports.DEBUG) {
process.stdout.write("node LOG: ");
}
if (_level >= exports.DEFAULT) {
console.log.apply(console, arguments)
}
}
/**
* Display message if level INFO or DEBUG.
*/
exports.info = function() { // Variable arguments
if (_level >= exports.DEBUG) {
process.stdout.write("node INFO: ");
}
if (_level >= exports.INFO) {
console.log.apply(console, arguments)
}
}
/**
* Display message if level DEBUG.
*/
exports.debug = function() { // Variable arguments
if (_level >= exports.DEBUG) {
process.stdout.write("node DEBUG: ");
console.log.apply(console, arguments)
}
}
/**
* Warning message
*/
exports.warn = function() { // Variable arguments
if (_level >= exports.DEBUG) {
process.stdout.write("node WARN: ");
}
console.log.apply(console, arguments)
}
/**
* Error message
*/
exports.error = function() { // Variable arguments
if (_level >= exports.DEBUG) {
process.stdout.write("node ERROR: ");
}
console.log.apply(console, arguments)
}
/**
* Display a fatal error message and bomb out.
*/
exports.fatalError = function(msg){
exports.error();
exports.error("-----------------------------------------------------------------------------");
exports.error("ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR");
exports.error("ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR");
exports.error("-----------------------------------------------------------------------------");
exports.error();
exports.error();
exports.error(" A fatal error has occurred and this command cannot continue.");
exports.error();
exports.error(" " + msg);
exports.error();
exports.error();
exports.error("-----------------------------------------------------------------------------");
exports.error("ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR");
exports.error("ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR");
exports.error("-----------------------------------------------------------------------------");
exports.error();
process.exit(1);
}