8000 Test for appender using subcategories. · yanxi123-com/log4js-node@492c45d · GitHub
[go: up one dir, main page]

Skip to content

Commit 492c45d

Browse files
author
Luis Malheiro
committed
Test for appender using subcategories.
1 parent ebbbea1 commit 492c45d

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

test/fileAppender-test.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,70 @@ vows.describe('log4js fileAppender').addBatch({
105105
);
106106
}
107107
},
108+
'fileAppender subcategories': {
109+
topic: function() {
110+
var that = this;
111+
112+
log4js.clearAppenders();
113+
114+
function addAppender(cat) {
115+
var testFile = path.join(__dirname, '/fa-subcategories-test-'+cat.join('-').replace(/\./g, "_")+'.log');
116+
remove(testFile);
117+
log4js.addAppender(require('../lib/appenders/file').appender(testFile), cat);
118+
return testFile;
119+
}
120+
121+
var file_sub1 = addAppender([ 'sub1']);
122+
123+
var file_sub1_sub12$sub1_sub13 = addAppender([ 'sub1.sub12', 'sub1.sub13' ]);
124+
125+
var file_sub1_sub12 = addAppender([ 'sub1.sub12' ]);
126+
127+
128+
var logger_sub1_sub12_sub123 = log4js.getLogger('sub1.sub12.sub123');
129+
130+
var logger_sub1_sub13_sub133 = log4js.getLogger('sub1.sub13.sub133');
131+
132+
var logger_sub1_sub14 = log4js.getLogger('sub1.sub14');
133+
134+
var logger_sub2 = log4js.getLogger('sub2');
135+
136+
137+
logger_sub1_sub12_sub123.info('sub1_sub12_sub123');
138+
139+
logger_sub1_sub13_sub133.info('sub1_sub13_sub133');
140+
141+
logger_sub1_sub14.info('sub1_sub14');
142+
143+
logger_sub2.info('sub2');
144+
145+
146+
setTimeout(function() {
147+
that.callback(null, {
148+
file_sub1: fs.readFileSync(file_sub1).toString(),
149+
file_sub1_sub12$sub1_sub13: fs.readFileSync(file_sub1_sub12$sub1_sub13).toString(),
150+
file_sub1_sub12: fs.readFileSync(file_sub1_sub12).toString()
151+
});
152+
}, 1000);
153+
},
154+
'check file contents': function (err, fileContents) {
155+
156+
// everything but category 'sub2'
157+
assert.match(fileContents.file_sub1, /^(\[\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d{3}\] \[INFO\] (sub1.sub12.sub123 - sub1_sub12_sub123|sub1.sub13.sub133 - sub1_sub13_sub133|sub1.sub14 - sub1_sub14)[\s\S]){3}$/);
158+
assert.ok(fileContents.file_sub1.match(/sub123/) && fileContents.file_sub1.match(/sub133/) && fileContents.file_sub1.match(/sub14/));
159+
assert.ok(!fileContents.file_sub1.match(/sub2/));
160+
161+
// only catgories starting with 'sub1.sub12' and 'sub1.sub13'
162+
assert.match(fileContents.file_sub1_sub12$sub1_sub13, /^(\[\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d{3}\] \[INFO\] (sub1.sub12.sub123 - sub1_sub12_sub123|sub1.sub13.sub133 - sub1_sub13_sub133)[\s\S]){2}$/);
163+
assert.ok(fileContents.file_sub1_sub12$sub1_sub13.match(/sub123/) && fileContents.file_sub1_sub12$sub1_sub13.match(/sub133/));
164+
assert.ok(!fileContents.file_sub1_sub12$sub1_sub13.match(/sub14|sub2/));
165+
166+
// only catgories starting with 'sub1.sub12'
167+
assert.match(fileContents.file_sub1_sub12, /^(\[\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d{3}\] \[INFO\] (sub1.sub12.sub123 - sub1_sub12_sub123)[\s\S]){1}$/);
168+
assert.ok(!fileContents.file_sub1_sub12.match(/sub14|sub2|sub13/));
169+
170+
}
171+
},
108172
'with a max file size and no backups': {
109173
topic: function() {
110174
var testFile = path.join(__dirname, '/fa-maxFileSize-test.log')

0 commit comments

Comments
 (0)
0