forked from slackapi/node-slack-sdk
-
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.
Logger getLevel()
- Loading branch information
Showing
4 changed files
with
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"require": ["ts-node/register", "source-map-support/register"], | ||
"timeout": 3000 | ||
} |
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,42 @@ | ||
require('mocha'); | ||
const { assert } = require('chai'); | ||
const { ConsoleLogger, LogLevel } = require('./index'); | ||
|
||
describe('logger', () => { | ||
it('should have the default LogLevel', () => { | ||
const logger = new ConsoleLogger(); | ||
assert.equal(logger.getLevel(), LogLevel.INFO); | ||
}); | ||
|
||
it('should set LogLevel corrrectly', () => { | ||
const logger = new ConsoleLogger(); | ||
assert.equal(logger.getLevel(), LogLevel.INFO); | ||
|
||
[LogLevel.DEBUG, LogLevel.ERROR, LogLevel.WARN, LogLevel.INFO].forEach((level) => { | ||
logger.setLevel(level); | ||
assert.equal(logger.getLevel(), level); | ||
}); | ||
}); | ||
|
||
it('should offer getLevel to test which level is currently set', () => { | ||
let largeObjectGenerated = false; | ||
function generateSomethingExpensive() { | ||
largeObjectGenerated = true; | ||
return JSON.stringify('{ description: "Something expensive to load" }'); | ||
} | ||
|
||
const logger = new ConsoleLogger(); | ||
logger.setLevel(LogLevel.INFO); | ||
if (logger.getLevel() === LogLevel.DEBUG) { | ||
const largeObj = generateSomethingExpensive(); | ||
logger.debug(`debug: ${largeObj}`); | ||
} | ||
assert.isFalse(largeObjectGenerated); | ||
|
||
logger.setLevel(LogLevel.DEBUG); | ||
if (logger.getLevel() === LogLevel.DEBUG) { | ||
generateSomethingExpensive(); | ||
} | ||
assert.isTrue(largeObjectGenerated); | ||
}); | ||
}); |
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