mirror of
https://github.com/log4js-node/log4js-node.git
synced 2025-12-08 19:26:01 +00:00
Merge pull request #739 from log4js-node/remove-rabbitmq
Remove RabbitMQ appender
This commit is contained in:
commit
5a3aef1fd5
@ -1,67 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* This appender is deprecated and will be removed in version 3.x
|
||||
* Please make any bug fixes or improvements to https://github.com/log4js-node/rabbitmq
|
||||
*/
|
||||
const amqplib = require('amqplib');
|
||||
|
||||
function rabbitmqAppender(config, layout) {
|
||||
const host = config.host || '127.0.0.1';
|
||||
const port = config.port || 5672;
|
||||
const username = config.username || 'guest';
|
||||
const password = config.password || 'guest';
|
||||
const exchange = config.exchange || '';
|
||||
const type = config.mq_type || '';
|
||||
const durable = config.durable || false;
|
||||
const routingKey = config.routing_key || 'logstash';
|
||||
const con = {
|
||||
protocol: 'amqp',
|
||||
hostname: host,
|
||||
port: port,
|
||||
username: username,
|
||||
password: password,
|
||||
locale: 'en_US',
|
||||
frameMax: 0,
|
||||
heartbeat: 0,
|
||||
vhost: '/',
|
||||
routing_key: routingKey,
|
||||
exchange: exchange,
|
||||
mq_type: type,
|
||||
durable: durable,
|
||||
};
|
||||
const clientconn = amqplib.connect(con);
|
||||
clientconn.publish = amqplib.connect(con).publish ? amqplib.connect(con).publish : (client, message) => {
|
||||
client.then((conn) => {
|
||||
const rn = conn.createChannel().then((ch) => {
|
||||
const ok = ch.assertExchange(exchange, type, { durable: durable });
|
||||
return ok.then(() => {
|
||||
ch.publish(exchange, routingKey, Buffer.from(message));
|
||||
return ch.close();
|
||||
});
|
||||
});
|
||||
return rn;
|
||||
}).catch(console.error);
|
||||
};
|
||||
function log(loggingEvent) {
|
||||
const message = layout(loggingEvent);
|
||||
clientconn.publish(clientconn, message);
|
||||
}
|
||||
log.shutdown = function () {
|
||||
clientconn.close();
|
||||
};
|
||||
|
||||
log.deprecated = '@log4js-node/rabbitmq';
|
||||
return log;
|
||||
}
|
||||
|
||||
function configure(config, layouts) {
|
||||
let layout = layouts.messagePassThroughLayout;
|
||||
if (config.layout) {
|
||||
layout = layouts.layout(config.layout.type, config.layout);
|
||||
}
|
||||
|
||||
return rabbitmqAppender(config, layout);
|
||||
}
|
||||
|
||||
module.exports.configure = configure;
|
||||
54
package-lock.json
generated
54
package-lock.json
generated
@ -82,19 +82,6 @@
|
||||
"integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=",
|
||||
"dev": true
|
||||
},
|
||||
"amqplib": {
|
||||
"version": "0.5.2",
|
||||
"resolved": "https://registry.npmjs.org/amqplib/-/amqplib-0.5.2.tgz",
|
||||
"integrity": "sha512-l9mCs6LbydtHqRniRwYkKdqxVa6XMz3Vw1fh+2gJaaVgTM6Jk3o8RccAKWKtlhT1US5sWrFh+KKxsVUALURSIA==",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"bitsyntax": "~0.0.4",
|
||||
"bluebird": "^3.4.6",
|
||||
"buffer-more-ints": "0.0.2",
|
||||
"readable-stream": "1.x >=1.1.9",
|
||||
"safe-buffer": "^5.0.1"
|
||||
}
|
||||
},
|
||||
"ansi-escapes": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.1.0.tgz",
|
||||
@ -233,19 +220,11 @@
|
||||
"integrity": "sha512-3/qRXczDi2Cdbz6jE+W3IflJOutRVica8frpBn14de1mBOkzDo+6tY33kNhvkw54Kn3PzRRD2VnGbGPcTAk4sw==",
|
||||
"dev": true
|
||||
},
|
||||
"bitsyntax": {
|
||||
"version": "0.0.4",
|
||||
"resolved": "https://registry.npmjs.org/bitsyntax/-/bitsyntax-0.0.4.tgz",
|
||||
"integrity": "sha1-6xDMb4K4xJDj6FaY8H6D1G4MuoI=",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"buffer-more-ints": "0.0.2"
|
||||
}
|
||||
},
|
||||
"bluebird": {
|
||||
"version": "3.5.1",
|
||||
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz",
|
||||
"integrity": "sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA=="
|
||||
"integrity": "sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA==",
|
||||
"dev": true
|
||||
},
|
||||
"brace-expansion": {
|
||||
"version": "1.1.11",
|
||||
@ -263,11 +242,6 @@
|
||||
"integrity": "sha512-c5mRlguI/Pe2dSZmpER62rSCu0ryKmWddzRYsuXc50U2/g8jMOulc31VZMa4mYx31U5xsmSOpDCgH88Vl9cDGQ==",
|
||||
"dev": true
|
||||
},
|
||||
"buffer-more-ints": {
|
||||
"version": "0.0.2",
|
||||
"resolved": "https://registry.npmjs.org/buffer-more-ints/-/buffer-more-ints-0.0.2.tgz",
|
||||
"integrity": "sha1-JrOIXRD6E9t/wBquOquHAZngEkw="
|
||||
},
|
||||
"builtin-modules": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz",
|
||||
@ -1954,12 +1928,6 @@
|
||||
"integrity": "sha1-Sw2hRCEE0bM2NA6AeX6GXPOffXI=",
|
||||
"dev": true
|
||||
},
|
||||
"isarray": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
|
||||
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=",
|
||||
"optional": true
|
||||
},
|
||||
"isexe": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
|
||||
@ -5659,18 +5627,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "1.1.14",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
|
||||
"integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"core-util-is": "~1.0.0",
|
||||
"inherits": "~2.0.1",
|
||||
"isarray": "0.0.1",
|
||||
"string_decoder": "~0.10.x"
|
||||
}
|
||||
},
|
||||
"redent": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/redent/-/redent-2.0.0.tgz",
|
||||
@ -6039,12 +5995,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"string_decoder": {
|
||||
"version": "0.10.31",
|
||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
|
||||
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
|
||||
"optional": true
|
||||
},
|
||||
"strip-ansi": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
|
||||
|
||||
@ -63,8 +63,7 @@
|
||||
"validate-commit-msg": "^2.14.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"axios": "^0.15.3",
|
||||
"amqplib": "^0.5.2"
|
||||
"axios": "^0.15.3"
|
||||
},
|
||||
"browser": {
|
||||
"os": false
|
||||
|
||||
@ -1,126 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const test = require('tap').test;
|
||||
const sandbox = require('@log4js-node/sandboxed-module');
|
||||
const appender = require('../../lib/appenders/rabbitmq');
|
||||
|
||||
function setupLogging(category, options) {
|
||||
const fakeRabbitmq = {
|
||||
msgs: [],
|
||||
connect: function (conn) {
|
||||
this.port = conn.port;
|
||||
this.host = conn.hostname;
|
||||
this.username = conn.username;
|
||||
this.password = conn.password;
|
||||
this.routing_key = conn.routing_key;
|
||||
this.exchange = conn.exchange;
|
||||
this.mq_type = conn.mq_type;
|
||||
this.durable = conn.durable;
|
||||
return {
|
||||
publish: function (client, message) {
|
||||
fakeRabbitmq.msgs.push(message);
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const fakeConsole = {
|
||||
log: () => {},
|
||||
errors: [],
|
||||
error: function (msg) {
|
||||
this.errors.push(msg);
|
||||
}
|
||||
};
|
||||
|
||||
const log4js = sandbox.require('../../lib/log4js', {
|
||||
requires: {
|
||||
amqplib: fakeRabbitmq,
|
||||
},
|
||||
globals: {
|
||||
console: fakeConsole
|
||||
}
|
||||
});
|
||||
log4js.configure({
|
||||
appenders: { rabbitmq: options },
|
||||
categories: { default: { appenders: ['rabbitmq'], level: 'trace' } }
|
||||
});
|
||||
|
||||
return {
|
||||
logger: log4js.getLogger(category),
|
||||
fakeRabbitmq: fakeRabbitmq,
|
||||
fakeConsole: fakeConsole
|
||||
};
|
||||
}
|
||||
|
||||
test('log4js rabbitmqAppender', (batch) => {
|
||||
batch.test('should export a configure function', (t) => {
|
||||
t.type(appender.configure, 'function');
|
||||
t.end();
|
||||
});
|
||||
|
||||
batch.test('rabbitmq setup', (t) => {
|
||||
const result = setupLogging('rabbitmq setup', {
|
||||
host: '123.123.123.123',
|
||||
port: 5672,
|
||||
username: 'guest',
|
||||
password: 'guest',
|
||||
routing_key: 'logstash',
|
||||
exchange: 'exchange_logs',
|
||||
mq_type: 'direct',
|
||||
durable: true,
|
||||
type: 'rabbitmq',
|
||||
layout: {
|
||||
type: 'pattern',
|
||||
pattern: 'cheese %m'
|
||||
}
|
||||
});
|
||||
|
||||
result.logger.info('Log event #1');
|
||||
|
||||
t.test('rabbitmq credentials should match', (assert) => {
|
||||
assert.equal(result.fakeRabbitmq.host, '123.123.123.123');
|
||||
assert.equal(result.fakeRabbitmq.port, 5672);
|
||||
assert.equal(result.fakeRabbitmq.username, 'guest');
|
||||
assert.equal(result.fakeRabbitmq.password, 'guest');
|
||||
assert.equal(result.fakeRabbitmq.routing_key, 'logstash');
|
||||
assert.equal(result.fakeRabbitmq.exchange, 'exchange_logs');
|
||||
assert.equal(result.fakeRabbitmq.mq_type, 'direct');
|
||||
assert.equal(result.fakeRabbitmq.durable, true);
|
||||
assert.equal(result.fakeRabbitmq.msgs.length, 1, 'should be one message only');
|
||||
assert.equal(result.fakeRabbitmq.msgs[0], 'cheese Log event #1');
|
||||
assert.end();
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
batch.test('default values', (t) => {
|
||||
const setup = setupLogging('defaults', {
|
||||
type: 'rabbitmq'
|
||||
});
|
||||
|
||||
setup.logger.info('just testing');
|
||||
|
||||
t.test('should use localhost', (assert) => {
|
||||
assert.equal(setup.fakeRabbitmq.host, '127.0.0.1');
|
||||
assert.equal(setup.fakeRabbitmq.port, 5672);
|
||||
assert.equal(setup.fakeRabbitmq.username, 'guest');
|
||||
assert.equal(setup.fakeRabbitmq.password, 'guest');
|
||||
assert.equal(setup.fakeRabbitmq.exchange, '');
|
||||
assert.equal(setup.fakeRabbitmq.mq_type, '');
|
||||
assert.equal(setup.fakeRabbitmq.durable, false);
|
||||
assert.equal(setup.fakeRabbitmq.routing_key, 'logstash');
|
||||
assert.end();
|
||||
});
|
||||
|
||||
t.test('should use message pass through layout', (assert) => {
|
||||
assert.equal(setup.fakeRabbitmq.msgs.length, 1);
|
||||
assert.equal(setup.fakeRabbitmq.msgs[0], 'just testing');
|
||||
assert.end();
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
batch.end();
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user