newLevel-test.js
4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
"use strict";
var vows = require('vows')
, assert = require('assert')
, Level = require('../lib/levels')
, log4js = require('../lib/log4js')
, loggerModule = require('../lib/logger')
, Logger = loggerModule.Logger;
vows.describe('../lib/logger').addBatch({
'creating a new log level': {
topic: function () {
Level.forName("DIAG", 6000);
return new Logger();
},
'should export new log level in levels module': function (logger) {
assert.isDefined(Level.DIAG);
assert.equal(Level.DIAG.levelStr, "DIAG");
assert.equal(Level.DIAG.level, 6000);
},
'should create named function on logger prototype': function(logger) {
assert.isFunction(logger.diag);
},
'should create isLevelEnabled function on logger prototype': function(logger) {
assert.isFunction(logger.isDiagEnabled);
},
},
'creating a new log level with underscores': {
topic: function () {
Level.forName("NEW_LEVEL_OTHER", 6000);
return new Logger();
},
'should export new log level to levels module': function (logger) {
assert.isDefined(Level.NEW_LEVEL_OTHER);
assert.equal(Level.NEW_LEVEL_OTHER.levelStr, "NEW_LEVEL_OTHER");
assert.equal(Level.NEW_LEVEL_OTHER.level, 6000);
},
'should create named function on logger prototype in camel case': function(logger) {
assert.isFunction(logger.newLevelOther);
},
'should create named isLevelEnabled function on logger prototype in camel case':
function(logger) {
assert.isFunction(logger.isNewLevelOtherEnabled);
}
},
'creating log events containing newly created log level': {
topic: function() {
var events = [],
logger = new Logger();
logger.addListener("log", function (logEvent) { events.push(logEvent); });
logger.log(Level.forName("LVL1", 6000), "Event 1");
logger.log(Level.getLevel("LVL1"), "Event 2");
logger.log("LVL1", "Event 3");
logger.lvl1("Event 4");
logger.setLevel(Level.forName("LVL2", 7000));
logger.lvl1("Event 5");
return events;
},
'should show log events with new log level': function(events) {
assert.equal(events[0].level.toString(), "LVL1");
assert.equal(events[0].data[0], "Event 1");
assert.equal(events[1].level.toString(), "LVL1");
assert.equal(events[1].data[0], "Event 2");
assert.equal(events[2].level.toString(), "LVL1");
assert.equal(events[2].data[0], "Event 3");
assert.equal(events[3].level.toString(), "LVL1");
assert.equal(events[3].data[0], "Event 4");
},
'should not be present if min log level is greater than newly created level':
function(events) {
assert.equal(events.length, 4);
}
},
'creating a new log level with incorrect parameters': {
topic: function() {
log4js.levels.forName(9000, "FAIL_LEVEL_1");
log4js.levels.forName("FAIL_LEVEL_2");
return new Logger();
},
'should fail to create the level': function(logger) {
assert.isUndefined(Level.FAIL_LEVEL_1);
assert.isUndefined(Level.FAIL_LEVEL_2);
}
},
'calling log with an undefined log level': {
topic: function() {
var events = [],
logger = new Logger();
logger.addListener("log", function (logEvent) { events.push(logEvent); });
logger.log("LEVEL_DOES_NEXT_EXIST", "Event 1");
logger.log(Level.forName("LEVEL_DOES_NEXT_EXIST"), "Event 2");
return events;
},
'should fallback to the default log level (INFO)': function(events) {
assert.equal(events[0].level.toString(), "INFO");
assert.equal(events[1].level.toString(), "INFO");
}
},
'creating a new level with an existing level name': {
topic: function() {
var events = [],
logger = new Logger();
logger.addListener("log", function (logEvent) { events.push(logEvent); });
logger.log(log4js.levels.forName("MY_LEVEL", 9000), "Event 1");
logger.log(log4js.levels.forName("MY_LEVEL", 8000), "Event 1");
return events;
},
'should override the existing log level': function(events) {
assert.equal(events[0].level.level, 9000);
assert.equal(events[1].level.level, 8000);
}
}
}).exportTo(module);