Not sure why these were classes to begin with
This commit is contained in:
parent
7379ce5eea
commit
f5de644af7
|
@ -27,10 +27,10 @@ var Logger = module.exports = {};
|
||||||
//
|
//
|
||||||
// Returns the new logger instance
|
// Returns the new logger instance
|
||||||
Logger.setup = function setup(logger) {
|
Logger.setup = function setup(logger) {
|
||||||
if (logger == null) { logger = new BasicLogger(); }
|
if (logger == null) { logger = BasicLogger; }
|
||||||
|
|
||||||
if (logger === false) {
|
if (logger === false) {
|
||||||
this.logger = new NullLogger();
|
this.logger = NullLogger;
|
||||||
} else {
|
} else {
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +1,24 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// The BasicLogger pushes stuff to console.log. Nothing more, nothing less.
|
|
||||||
var BasicLogger = module.exports = function BasicLogger() {};
|
|
||||||
|
|
||||||
BasicLogger.prototype.toString = function() {
|
|
||||||
return "BasicLogger";
|
|
||||||
};
|
|
||||||
|
|
||||||
var getArgs = function(args) {
|
var getArgs = function(args) {
|
||||||
return args.length >= 1 ? [].slice.call(args, 0) : [];
|
return args.length >= 1 ? [].slice.call(args, 0) : [];
|
||||||
};
|
};
|
||||||
|
|
||||||
var logString = function(type) {
|
var logString = function(type) {
|
||||||
var upcase = String(type).toUpperCase(),
|
var time = new Date().toISOString(),
|
||||||
time = new Date().toISOString();
|
type = String(type).toUpperCase(),
|
||||||
|
padded = String(" " + type).slice(-5);
|
||||||
|
|
||||||
var padded = String(" " + upcase).slice(-5);
|
return type[0] + ", [" + time + "] " + padded + " -- :";
|
||||||
|
|
||||||
return upcase[0] + ", [" + time + "] " + padded + " -- :";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// The BasicLogger logs to console.log
|
||||||
|
var BasicLogger = module.exports = {
|
||||||
|
toString: function() { return "BasicLogger"; },
|
||||||
|
};
|
||||||
|
|
||||||
['debug', 'info', 'warn', 'error', 'fatal'].forEach(function(type) {
|
['debug', 'info', 'warn', 'error', 'fatal'].forEach(function(type) {
|
||||||
BasicLogger.prototype[type] = function() {
|
BasicLogger[type] = function() {
|
||||||
var args = getArgs(arguments);
|
var args = getArgs(arguments);
|
||||||
return console.log.apply(console, [].concat(logString(type), args));
|
return console.log.apply(console, [].concat(logString(type), args));
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
// The NullLogger is designed for cases where you want absolutely nothing to
|
// The NullLogger is designed for cases where you want absolutely nothing to
|
||||||
// print to anywhere. Every proxied method from the Logger returns a noop.
|
// print to anywhere. Every proxied method from the Logger returns a noop.
|
||||||
var NullLogger = module.exports = function NullLogger() {};
|
var NullLogger = module.exports = {
|
||||||
|
toString: function() { return "NullLogger"; }
|
||||||
NullLogger.prototype.toString = function() {
|
|
||||||
return "NullLogger";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
NullLogger.prototype.debug = function() {};
|
['debug', 'info', 'warn', 'error', 'fatal'].forEach(function(type) {
|
||||||
NullLogger.prototype.info = function() {};
|
NullLogger[type] = function() {};
|
||||||
NullLogger.prototype.warn = function() {};
|
});
|
||||||
NullLogger.prototype.error = function() {};
|
|
||||||
NullLogger.prototype.fatal = function() {};
|
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var BasicLogger = source('logger/basic_logger');
|
var logger = source('logger/basic_logger');
|
||||||
|
|
||||||
var date = new Date(0).toISOString();
|
var date = new Date(0).toISOString();
|
||||||
|
|
||||||
describe('BasicLogger', function() {
|
describe('BasicLogger', function() {
|
||||||
var logger = new BasicLogger(),
|
var clock;
|
||||||
clock;
|
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
stub(console, 'log');
|
stub(console, 'log');
|
||||||
|
|
Loading…
Reference in New Issue