changed the way appenders are loaded, so that they don't need to include log4js as a direct dependency

This commit is contained in:
Gareth Jones
2013-09-15 14:37:01 +10:00
parent 245b2e3b1a
commit 491c2709e7
12 changed files with 350 additions and 185 deletions

View File

@@ -30,12 +30,12 @@ describe('log4js in a cluster', function() {
cb(worker);
}
},
'./appenders/console': {
configure: function() {
'./appenders/console': function() {
return function() {
return function(event) {
events.push(event);
};
}
};
}
}
}

View File

@@ -17,7 +17,7 @@ describe('../lib/appenders/console', function() {
}
}
)
, appender = appenderModule.configure(
, appender = appenderModule(require('../lib/layouts'))(
{ layout: { type: "messagePassThrough" } }
);

View File

@@ -17,7 +17,7 @@ describe('../lib/appenders/dateFile', function() {
var files = [], initialListeners;
before(function() {
var dateFileAppender = require('../lib/appenders/dateFile'),
var dateFileAppender = require('../lib/appenders/dateFile')({ basicLayout: function() {} }),
count = 5,
logfile;
@@ -25,7 +25,7 @@ describe('../lib/appenders/dateFile', function() {
while (count--) {
logfile = path.join(__dirname, 'datefa-default-test' + count + '.log');
dateFileAppender.configure({
dateFileAppender({
filename: logfile
});
files.push(logfile);
@@ -69,10 +69,10 @@ describe('../lib/appenders/dateFile', function() {
}
}
}
);
)({ basicLayout: function() {} });
for (var i=0; i < 5; i += 1) {
dateFileAppender.configure({
dateFileAppender({
filename: 'test' + i
});
}

View File

@@ -75,9 +75,9 @@ describe('log4js fileAppender', function() {
}
}
}
);
)(require('../lib/layouts'));
for (var i=0; i < 5; i += 1) {
fileAppender.appender('test' + i, null, 100);
fileAppender({ filename: 'test' + i, maxLogSize: 100 });
}
openedFiles.should.not.be.empty;
exitListener();
@@ -317,8 +317,8 @@ describe('log4js fileAppender', function() {
}
}
}
);
fileAppender.configure({
)(require('../lib/layouts'));
fileAppender({
filename: 'test1.log',
maxLogSize: 100
});

View File

@@ -178,10 +178,10 @@ describe('../lib/log4js', function() {
'../lib/log4js',
{
requires: {
'cheese': {
configure: function() {
'cheese': function() {
return function() {
return function(evt) { events.push(evt); };
}
};
}
}
}
@@ -201,6 +201,102 @@ describe('../lib/log4js', function() {
});
it('should only load third-party appenders once', function() {
var moduleCalled = 0
, log4js_sandbox = sandbox.require(
'../lib/log4js',
{
requires: {
'cheese': function() {
moduleCalled += 1;
return function() {
return function() {};
};
}
}
}
);
log4js_sandbox.configure({
appenders: {
"thing1": { type: "cheese" },
"thing2": { type: "cheese" }
},
categories: {
default: { level: "DEBUG", appenders: [ "thing1", "thing2" ] }
}
});
moduleCalled.should.eql(1);
});
it('should pass layouts and levels to appender modules', function() {
var layouts
, levels
, log4js_sandbox = sandbox.require(
'../lib/log4js',
{
requires: {
'cheese': function(arg1, arg2) {
layouts = arg1;
levels = arg2;
return function() {
return function() {};
};
}
}
}
);
log4js_sandbox.configure({
appenders: {
"thing": { type: "cheese" }
},
categories: {
"default": { level: "debug", appenders: [ "thing" ] }
}
});
layouts.should.have.property("basicLayout");
levels.should.have.property("toLevel");
});
it('should pass config and appenderByName to appender makers', function() {
var otherAppender = function() { /* I do nothing */ }
, config
, other
, log4js_sandbox = sandbox.require(
'../lib/log4js',
{
requires: {
'other': function() {
return function() {
return otherAppender;
};
},
'cheese': function() {
return function(arg1, arg2) {
config = arg1;
other = arg2("other");
return function() {};
};
}
}
}
);
log4js_sandbox.configure({
appenders: {
"other": { type: "other" },
"thing": { type: "cheese", something: "something" }
},
categories: {
default: { level: "debug", appenders: [ "other", "thing" ] }
}
});
other.should.equal(otherAppender);
config.should.have.property("something", "something");
});
it('should complain about unknown appenders', function() {
(function() {
log4js.configure({
@@ -221,10 +317,10 @@ describe('../lib/log4js', function() {
'../lib/log4js',
{
requires: {
'cheese': {
configure: function() {
'cheese': function() {
return function() {
return function(event) { events.push(event); };
}
};
}
}
}
@@ -244,10 +340,10 @@ describe('../lib/log4js', function() {
'../lib/log4js',
{
requires: {
'cheese': {
configure: function() {
'cheese': function() {
return function() {
return function(event) { events.push(event); };
}
};
}
}
}
@@ -273,10 +369,10 @@ describe('../lib/log4js', function() {
'../lib/log4js',
{
requires: {
'cheese': {
configure: function() {
'cheese': function() {
return function() {
return function(event) { events.push(event); };
}
};
}
}
}
@@ -301,10 +397,10 @@ describe('../lib/log4js', function() {
'../lib/log4js',
{
requires: {
'./appenders/console': {
configure: function() {
'./appenders/console': function() {
return function() {
return function(event) { events.push(event); };
}
};
}
}
}

View File

@@ -11,8 +11,8 @@ describe('log level filter', function() {
var log4js_sandboxed = sandbox.require(
'../lib/log4js',
{ requires:
{ './appenders/console':
{ configure: function() { return function(evt) { events.push(evt); }; } }
{ './appenders/console': function() {
return function() { return function(evt) { events.push(evt); }; }; }
}
}
);