-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jonathan lavon
committed
Nov 10, 2015
1 parent
85be07a
commit 21f9fc8
Showing
3 changed files
with
144 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
npm-debug.log |
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,93 @@ | ||
var log4js = require('log4js'); | ||
var assert = require("assert"); | ||
|
||
describe('test filter', function(){ | ||
|
||
it ('should limit to 1 log', function(){ | ||
var logEvents = []; | ||
log4js.clearAppenders(); | ||
var appender = require('../lib/filter') | ||
.appender({TRACE:1}, | ||
1000, | ||
function(evt) { logEvents.push(evt); } | ||
); | ||
log4js.addAppender(appender, ["app"]); | ||
|
||
var logger = log4js.getLogger("app"); | ||
logger.info('hey'); | ||
logger.info('hey'); | ||
logger.info('hey'); | ||
|
||
assert.equal(logEvents.length,1, 'Did not limit calls'); | ||
}); | ||
|
||
it ('should limit to 1 error log', function(){ | ||
var logEvents = []; | ||
log4js.clearAppenders(); | ||
var appender = require('../lib/filter') | ||
.appender({ | ||
TRACE:1, | ||
ERROR:1 | ||
}, | ||
500, | ||
function(evt) { logEvents.push(evt); } | ||
); | ||
log4js.addAppender(appender, ["app"]); | ||
|
||
var logger = log4js.getLogger("app"); | ||
logger.error('hey'); | ||
logger.info('hey'); | ||
logger.trace('hey'); | ||
|
||
assert.equal(logEvents.length,1, 'Did not limit calls'); | ||
assert.equal(logEvents[0].level.level, log4js.levels.ERROR.level, 'Not correct error'); | ||
}); | ||
|
||
it ('should limit to 2 logs', function(){ | ||
var logEvents = []; | ||
log4js.clearAppenders(); | ||
var appender = require('../lib/filter') | ||
.appender({ | ||
TRACE:1, | ||
ERROR:1 | ||
}, | ||
500, | ||
function(evt) { logEvents.push(evt); } | ||
); | ||
log4js.addAppender(appender, ["app"]); | ||
|
||
var logger = log4js.getLogger("app"); | ||
logger.info('hey'); | ||
logger.error('hey'); | ||
logger.trace('hey'); | ||
|
||
assert.equal(logEvents.length,2, 'Did not limit calls'); | ||
assert.equal(logEvents[0].level.level, log4js.levels.INFO.level, 'Not correct error'); | ||
assert.equal(logEvents[1].level.level, log4js.levels.ERROR.level, 'Not correct error'); | ||
}); | ||
|
||
it ('should limit to 2 logs, with time limit', function(done){ | ||
var logEvents = []; | ||
log4js.clearAppenders(); | ||
var appender = require('../lib/filter') | ||
.appender({TRACE:1}, | ||
500, | ||
function(evt) { logEvents.push(evt); } | ||
); | ||
log4js.addAppender(appender, ["app"]); | ||
|
||
var logger = log4js.getLogger("app"); | ||
logger.info('hey'); | ||
logger.info('hey'); | ||
logger.info('hey'); | ||
|
||
assert.equal(logEvents.length,1, 'Did not limit calls'); | ||
setTimeout(function(){ | ||
logger.info('hey'); | ||
logger.info('hey'); | ||
logger.info('hey'); | ||
assert.equal(logEvents.length,2, 'Did not limit calls'); | ||
done(); | ||
}, 800); | ||
}); | ||
}); |