forked from es-analysis/plato
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve logger to call proper console api
solved es-analysis#185 (redirecting stderr in shell)
- Loading branch information
1 parent
2c2e09c
commit 2a06276
Showing
2 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
'use strict'; | ||
var Logger = require('../lib/logger'); | ||
|
||
exports['logger'] = { | ||
setUp: function(done) { | ||
// setup here | ||
this._console = console; | ||
console = { | ||
msg: {}, | ||
trace: function(msg) { | ||
this.msg.trace = msg; | ||
}, | ||
log: function(msg) { | ||
this.msg.log = msg; | ||
}, | ||
info: function(msg) { | ||
this.msg.info = msg; | ||
}, | ||
warn: function(msg) { | ||
this.msg.warn = msg; | ||
}, | ||
error: function(msg) { | ||
this.msg.error = msg; | ||
} | ||
}; | ||
done(); | ||
}, | ||
tearDown: function (done) { | ||
// clean up | ||
console = this._console; | ||
done(); | ||
}, | ||
'TRACE LEVEL': function(test) { | ||
var message = "called"; | ||
var log = new Logger(Logger.TRACE); | ||
|
||
test.expect(5); | ||
|
||
log.trace(message); | ||
log.debug(message); | ||
log.info(message); | ||
log.warning(message); | ||
log.error(message); | ||
|
||
test.equal(console.msg.trace, message, 'should trace message'); | ||
test.equal(console.msg.log, message, 'should log message'); | ||
test.equal(console.msg.info, message, 'should info message'); | ||
test.equal(console.msg.warn, message, 'should warn message'); | ||
test.equal(console.msg.error, message, 'should error message'); | ||
|
||
test.done(); | ||
}, | ||
'DEBUG LEVEL': function(test) { | ||
var message = "called"; | ||
var log = new Logger(Logger.DEBUG); | ||
|
||
test.expect(5); | ||
|
||
log.trace(message); | ||
log.debug(message); | ||
log.info(message); | ||
log.warning(message); | ||
log.error(message); | ||
|
||
test.equal(console.msg.trace, undefined, 'should not trace message'); | ||
test.equal(console.msg.log, message, 'should log message'); | ||
test.equal(console.msg.info, message, 'should info message'); | ||
test.equal(console.msg.warn, message, 'should warn message'); | ||
test.equal(console.msg.error, message, 'should error message'); | ||
|
||
test.done(); | ||
}, | ||
'INFO LEVEL': function(test) { | ||
var message = "called"; | ||
var log = new Logger(Logger.INFO); | ||
|
||
test.expect(5); | ||
|
||
log.trace(message); | ||
log.debug(message); | ||
log.info(message); | ||
log.warning(message); | ||
log.error(message); | ||
|
||
test.equal(console.msg.trace, undefined, 'should not trace message'); | ||
test.equal(console.msg.log, undefined, 'should not log message'); | ||
test.equal(console.msg.info, message, 'should info message'); | ||
test.equal(console.msg.warn, message, 'should warn message'); | ||
test.equal(console.msg.error, message, 'should error message'); | ||
|
||
test.done(); | ||
}, | ||
'WARNING LEVEL': function(test) { | ||
var message = "called"; | ||
var log = new Logger(Logger.WARNING); | ||
|
||
test.expect(5); | ||
|
||
log.trace(message); | ||
log.debug(message); | ||
log.info(message); | ||
log.warning(message); | ||
log.error(message); | ||
|
||
test.equal(console.msg.trace, undefined, 'should not trace message'); | ||
test.equal(console.msg.log, undefined, 'should not log message'); | ||
test.equal(console.msg.info, undefined, 'should not info message'); | ||
test.equal(console.msg.warn, message, 'should warn message'); | ||
test.equal(console.msg.error, message, 'should error message'); | ||
|
||
test.done(); | ||
}, | ||
'ERROR LEVEL': function(test) { | ||
var message = "called"; | ||
var log = new Logger(Logger.ERROR); | ||
|
||
test.expect(5); | ||
|
||
log.trace(message); | ||
log.debug(message); | ||
log.info(message); | ||
log.warning(message); | ||
log.error(message); | ||
|
||
test.equal(console.msg.trace, undefined, 'should not trace message'); | ||
test.equal(console.msg.log, undefined, 'should not log message'); | ||
test.equal(console.msg.info, undefined, 'should not info message'); | ||
test.equal(console.msg.warn, undefined, 'should not warn message'); | ||
test.equal(console.msg.error, message, 'should error message'); | ||
|
||
test.done(); | ||
} | ||
}; |