Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: configure log levels & log provider
test: logger
- Loading branch information
Showing
3 changed files
with
208 additions
and
32 deletions.
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
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,153 @@ | ||
var expect = require('chai').expect; | ||
var Logger = require('../lib/logger'); | ||
|
||
describe('Logger', function () { | ||
var logger; | ||
var logMessage, debugMessage, infoMessage, warnMessage, errorMessage; | ||
|
||
beforeEach(function () { | ||
logMessage = undefined; | ||
debugMessage = undefined; | ||
infoMessage = undefined; | ||
warnMessage = undefined; | ||
errorMessage = undefined; | ||
}); | ||
|
||
beforeEach(function () { | ||
logger = Logger.getInstance(); | ||
}); | ||
|
||
beforeEach(function () { | ||
logger.setProvider(function (provider) { | ||
provider.log = function (message) {logMessage = message}; | ||
provider.debug = function (message) {debugMessage = message}; | ||
provider.info = function (message) {infoMessage = message}; | ||
provider.warn = function (message) {warnMessage = message}; | ||
provider.error = function (message) {errorMessage = message}; | ||
|
||
return provider; | ||
}); | ||
}); | ||
|
||
describe('logging with different levels', function () { | ||
beforeEach(function () { | ||
logger.log('log'); | ||
logger.debug('debug'); | ||
logger.info('info'); | ||
logger.warn('warn'); | ||
logger.error('error'); | ||
}); | ||
|
||
describe('level: debug', function () { | ||
beforeEach(function () { | ||
logger.setLevel('debug'); | ||
}); | ||
|
||
it('should log .log() messages', function () { | ||
expect(logMessage).to.equal('log'); | ||
}); | ||
it('should log .debug() messages', function () { | ||
expect(debugMessage).to.equal('debug'); | ||
}); | ||
it('should log .info() messages', function () { | ||
expect(infoMessage).to.equal('info'); | ||
}); | ||
it('should log .warn() messages', function () { | ||
expect(warnMessage).to.equal('warn'); | ||
}); | ||
it('should log .error() messages', function () { | ||
expect(errorMessage).to.equal('error'); | ||
}); | ||
}); | ||
|
||
describe('level: info', function () { | ||
beforeEach(function () { | ||
logger.setLevel('info'); | ||
}); | ||
|
||
it('should log .log() messages', function () { | ||
expect(logMessage).to.equal('log'); | ||
}); | ||
it('should not log .debug() messages', function () { | ||
expect(debugMessage).to.equal(undefined); | ||
}); | ||
it('should log .info() messages', function () { | ||
expect(infoMessage).to.equal('info'); | ||
}); | ||
it('should log .warn() messages', function () { | ||
expect(warnMessage).to.equal('warn'); | ||
}); | ||
it('should log .error() messages', function () { | ||
expect(errorMessage).to.equal('error'); | ||
}); | ||
}); | ||
|
||
describe('level: warn', function () { | ||
beforeEach(function () { | ||
logger.setLevel('warn'); | ||
}); | ||
|
||
it('should log .log() messages', function () { | ||
expect(logMessage).to.equal('log'); | ||
}); | ||
it('should not log .debug() messages', function () { | ||
expect(debugMessage).to.equal(undefined); | ||
}); | ||
it('should not log .info() messages', function () { | ||
expect(infoMessage).to.equal(undefined); | ||
}); | ||
it('should log .warn() messages', function () { | ||
expect(warnMessage).to.equal('warn'); | ||
}); | ||
it('should log .error() messages', function () { | ||
expect(errorMessage).to.equal('error'); | ||
}); | ||
}); | ||
|
||
describe('level: error', function () { | ||
beforeEach(function () { | ||
logger.setLevel('error'); | ||
}); | ||
|
||
it('should log .log() messages', function () { | ||
expect(logMessage).to.equal('log'); | ||
}); | ||
it('should not log .debug() messages', function () { | ||
expect(debugMessage).to.equal(undefined); | ||
}); | ||
it('should not log .info() messages', function () { | ||
expect(infoMessage).to.equal(undefined); | ||
}); | ||
it('should log .warn() messages', function () { | ||
expect(warnMessage).to.equal(undefined); | ||
}); | ||
it('should log .error() messages', function () { | ||
expect(errorMessage).to.equal('error'); | ||
}); | ||
}); | ||
|
||
describe('level: silent', function () { | ||
beforeEach(function () { | ||
logger.setLevel('silent'); | ||
}); | ||
|
||
it('should log .log() messages', function () { | ||
expect(logMessage).to.equal('log'); | ||
}); | ||
it('should not log .debug() messages', function () { | ||
expect(debugMessage).to.equal(undefined); | ||
}); | ||
it('should not log .info() messages', function () { | ||
expect(infoMessage).to.equal(undefined); | ||
}); | ||
it('should not log .warn() messages', function () { | ||
expect(warnMessage).to.equal(undefined); | ||
}); | ||
it('should not log .error() messages', function () { | ||
expect(errorMessage).to.equal(undefined); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
|