Pass in all appender parameters to the Hook constructor so a port can be specified
This commit is contained in:
parent
07e920cc1b
commit
ced570413c
@ -157,6 +157,7 @@ This was mainly created for [cluster](https://github.com/LearnBoost/cluster), bu
|
||||
.use(cluster.pidfiles('run/pids'))
|
||||
.listen(3000);
|
||||
</pre>
|
||||
log4js-master/worker.json hookio appender parameters will be passed into the Hook constructor directly, so you can specify hook-port, hook-host etc.
|
||||
*NOTE* hook.io appender will currently (and probably indefinitely) explode if you enable hook.io debug because of the way log4js overrides console.log
|
||||
|
||||
## author (of this node version)
|
||||
|
@ -23,14 +23,14 @@ function deserializeLoggingEvent(loggingEvent) {
|
||||
};
|
||||
}
|
||||
|
||||
function createAppender(hookioOptions, actualAppender) {
|
||||
function createAppender(hookioOptions) {
|
||||
var loggerHook;
|
||||
if (hookioOptions.mode === 'master') {
|
||||
// Start the master hook, handling the actual logging
|
||||
loggerHook = new Logger({ name: hookioOptions.name, debug: hookioOptions.debug, actualAppender: actualAppender });
|
||||
loggerHook = new Logger(hookioOptions);
|
||||
} else {
|
||||
// Start a worker, just emitting events for a master
|
||||
loggerHook = new Hook({ name: hookioOptions.name, debug: hookioOptions.debug });
|
||||
loggerHook = new Hook(hookioOptions);
|
||||
}
|
||||
loggerHook.start();
|
||||
|
||||
@ -45,10 +45,9 @@ function configure(config) {
|
||||
if (config.appender && config.mode === 'master') {
|
||||
log4js.loadAppender(config.appender.type);
|
||||
actualAppender = log4js.appenderMakers[config.appender.type](config.appender);
|
||||
config.actualAppender = actualAppender;
|
||||
}
|
||||
delete config.appender;
|
||||
delete config.type;
|
||||
return createAppender(config, actualAppender);
|
||||
return createAppender(config);
|
||||
}
|
||||
|
||||
exports.name = 'hookio';
|
||||
|
@ -3,7 +3,7 @@ var assert = require('assert');
|
||||
var sandbox = require('sandboxed-module');
|
||||
|
||||
function fancyResultingHookioAppender(opts) {
|
||||
var result = { ons: {}, emissions: {}, logged: [] };
|
||||
var result = { ons: {}, emissions: {}, logged: [], configs: [] };
|
||||
|
||||
var fakeLog4Js = {
|
||||
appenderMakers: {}
|
||||
@ -17,7 +17,7 @@ function fancyResultingHookioAppender(opts) {
|
||||
};
|
||||
};
|
||||
|
||||
var fakeHookIo = { Hook: function() { } };
|
||||
var fakeHookIo = { Hook: function(config) { result.configs.push(config); } };
|
||||
fakeHookIo.Hook.prototype.start = function () {
|
||||
result.startCalled = true;
|
||||
};
|
||||
@ -52,7 +52,7 @@ vows.describe('log4js hookioAppender').addBatch({
|
||||
'master': {
|
||||
topic: function() {
|
||||
var fancy = fancyResultingHookioAppender();
|
||||
var logger = fancy.theModule.configure({ name: 'ohno', mode: 'master', appender: { type: 'file' } });
|
||||
var logger = fancy.theModule.configure({ name: 'ohno', mode: 'master', 'hook-port': 5001, appender: { type: 'file' } });
|
||||
logger({ level: { levelStr: 'INFO' }, data: "ALRIGHTY THEN", startTime: '2011-10-27T03:53:16.031Z' });
|
||||
logger({ level: { levelStr: 'DEBUG' }, data: "OH WOW", startTime: '2011-10-27T04:53:16.031Z'});
|
||||
return fancy.theResult;
|
||||
@ -60,6 +60,8 @@ vows.describe('log4js hookioAppender').addBatch({
|
||||
|
||||
'should write to the actual appender': function (result) {
|
||||
assert.isTrue(result.startCalled);
|
||||
assert.equal(result.configs.length, 1);
|
||||
assert.equal(result.configs[0]['hook-port'], 5001);
|
||||
assert.equal(result.logged.length, 2);
|
||||
assert.equal(result.emissions['ohno::log'].length, 2);
|
||||
assert.equal(result.ons['*::ohno::log'].callingCount, 2);
|
||||
|
Loading…
Reference in New Issue
Block a user