2013-05-27 06:15:57 +08:00
|
|
|
"use strict";
|
|
|
|
var vows = require('vows')
|
|
|
|
, assert = require('assert');
|
2011-05-29 10:46:05 +08:00
|
|
|
|
|
|
|
vows.describe('log4js global loglevel').addBatch({
|
2013-05-27 06:15:57 +08:00
|
|
|
'global loglevel' : {
|
|
|
|
topic: function() {
|
|
|
|
var log4js = require('../lib/log4js');
|
|
|
|
return log4js;
|
|
|
|
},
|
2014-05-04 21:20:22 +08:00
|
|
|
|
2013-05-27 06:15:57 +08:00
|
|
|
'set global loglevel on creation': function(log4js) {
|
|
|
|
var log1 = log4js.getLogger('log1');
|
|
|
|
var level = 'OFF';
|
|
|
|
if (log1.level.toString() == level) {
|
|
|
|
level = 'TRACE';
|
|
|
|
}
|
|
|
|
assert.notEqual(log1.level.toString(), level);
|
2014-05-04 21:20:22 +08:00
|
|
|
|
2013-05-27 06:15:57 +08:00
|
|
|
log4js.setGlobalLogLevel(level);
|
|
|
|
assert.equal(log1.level.toString(), level);
|
2011-05-29 10:46:05 +08:00
|
|
|
|
2013-05-27 06:15:57 +08:00
|
|
|
var log2 = log4js.getLogger('log2');
|
|
|
|
assert.equal(log2.level.toString(), level);
|
|
|
|
},
|
2014-05-04 21:20:22 +08:00
|
|
|
|
2013-05-27 06:15:57 +08:00
|
|
|
'global change loglevel': function(log4js) {
|
|
|
|
var log1 = log4js.getLogger('log1');
|
|
|
|
var log2 = log4js.getLogger('log2');
|
|
|
|
var level = 'OFF';
|
|
|
|
if (log1.level.toString() == level) {
|
|
|
|
level = 'TRACE';
|
|
|
|
}
|
|
|
|
assert.notEqual(log1.level.toString(), level);
|
2014-05-04 21:20:22 +08:00
|
|
|
|
2013-05-27 06:15:57 +08:00
|
|
|
log4js.setGlobalLogLevel(level);
|
|
|
|
assert.equal(log1.level.toString(), level);
|
|
|
|
assert.equal(log2.level.toString(), level);
|
|
|
|
},
|
2011-05-29 10:46:05 +08:00
|
|
|
|
2013-05-27 06:15:57 +08:00
|
|
|
'override loglevel': function(log4js) {
|
|
|
|
var log1 = log4js.getLogger('log1');
|
|
|
|
var log2 = log4js.getLogger('log2');
|
|
|
|
var level = 'OFF';
|
|
|
|
if (log1.level.toString() == level) {
|
|
|
|
level = 'TRACE';
|
|
|
|
}
|
|
|
|
assert.notEqual(log1.level.toString(), level);
|
2014-05-04 21:20:22 +08:00
|
|
|
|
2013-05-27 06:15:57 +08:00
|
|
|
var oldLevel = log1.level.toString();
|
|
|
|
assert.equal(log2.level.toString(), oldLevel);
|
2014-05-04 21:20:22 +08:00
|
|
|
|
2013-05-27 06:15:57 +08:00
|
|
|
log2.setLevel(level);
|
|
|
|
assert.equal(log1.level.toString(), oldLevel);
|
|
|
|
assert.equal(log2.level.toString(), level);
|
|
|
|
assert.notEqual(oldLevel, level);
|
2014-05-04 21:20:22 +08:00
|
|
|
|
2013-05-27 06:15:57 +08:00
|
|
|
log2.removeLevel();
|
|
|
|
assert.equal(log1.level.toString(), oldLevel);
|
|
|
|
assert.equal(log2.level.toString(), oldLevel);
|
|
|
|
},
|
2014-05-04 21:20:22 +08:00
|
|
|
|
2013-05-27 06:15:57 +08:00
|
|
|
'preload loglevel': function(log4js) {
|
|
|
|
var log1 = log4js.getLogger('log1');
|
|
|
|
var level = 'OFF';
|
|
|
|
if (log1.level.toString() == level) {
|
|
|
|
level = 'TRACE';
|
|
|
|
}
|
|
|
|
assert.notEqual(log1.level.toString(), level);
|
2014-05-04 21:20:22 +08:00
|
|
|
|
2013-05-27 06:15:57 +08:00
|
|
|
var oldLevel = log1.level.toString();
|
|
|
|
log4js.getLogger('log2').setLevel(level);
|
2014-05-04 21:20:22 +08:00
|
|
|
|
2013-05-27 06:15:57 +08:00
|
|
|
assert.equal(log1.level.toString(), oldLevel);
|
2014-05-04 21:20:22 +08:00
|
|
|
|
2013-05-27 06:15:57 +08:00
|
|
|
// get again same logger but as different variable
|
|
|
|
var log2 = log4js.getLogger('log2');
|
|
|
|
assert.equal(log2.level.toString(), level);
|
|
|
|
assert.notEqual(oldLevel, level);
|
2014-05-04 21:20:22 +08:00
|
|
|
|
2013-05-27 06:15:57 +08:00
|
|
|
log2.removeLevel();
|
|
|
|
assert.equal(log1.level.toString(), oldLevel);
|
|
|
|
assert.equal(log2.level.toString(), oldLevel);
|
2014-05-04 21:20:22 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
'set level on all categories': function(log4js) {
|
|
|
|
// Get 2 loggers
|
|
|
|
var log1 = log4js.getLogger('log1');
|
|
|
|
var log2 = log4js.getLogger('log2');
|
|
|
|
|
|
|
|
// First a test with 2 categories with different levels
|
|
|
|
var config = {
|
|
|
|
'levels': {
|
|
|
|
'log1': 'ERROR',
|
|
|
|
'log2': 'WARN'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
log4js.configure(config);
|
|
|
|
|
|
|
|
// Check if the levels are set correctly
|
|
|
|
assert.equal('ERROR', log1.level.toString());
|
|
|
|
assert.equal('WARN', log2.level.toString());
|
|
|
|
|
|
|
|
log1.removeLevel();
|
|
|
|
log2.removeLevel();
|
|
|
|
|
|
|
|
// Almost identical test, but now we set
|
|
|
|
// level on all categories
|
|
|
|
var config2 = {
|
|
|
|
'levels': {
|
|
|
|
'[all]': 'DEBUG'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
log4js.configure(config2);
|
|
|
|
|
|
|
|
// Check if the loggers got the DEBUG level
|
|
|
|
assert.equal('DEBUG', log1.level.toString());
|
|
|
|
assert.equal('DEBUG', log2.level.toString());
|
2011-05-29 10:46:05 +08:00
|
|
|
}
|
2013-05-27 06:15:57 +08:00
|
|
|
}
|
2011-05-29 10:46:05 +08:00
|
|
|
}).export(module);
|