Merge branch 'jdell64-log4js-update-#706'

This commit is contained in:
Gareth Jones 2018-05-12 09:39:08 +10:00
commit 7d82f8271e
10 changed files with 837 additions and 626 deletions

1386
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -58,7 +58,7 @@
"husky": "^0.14.3",
"nyc": "^11.7.3",
"sandboxed-module": "^2.0.3",
"tap": "^10.7.3",
"tap": "^11.1.5",
"validate-commit-msg": "^2.14.0"
},
"optionalDependencies": {

View File

@ -2,8 +2,40 @@
const test = require('tap').test;
const sandbox = require('sandboxed-module');
const consoleAppender = require('../../lib/appenders/console');
test('log4js console appender', (batch) => {
batch.test('should export a configure function', (t) => {
t.type(consoleAppender.configure, 'function');
t.end();
});
batch.test('should use default layout if none specified', (t) => {
const messages = [];
const fakeConsole = {
log: function (msg) {
messages.push(msg);
}
};
const log4js = sandbox.require(
'../../lib/log4js',
{
globals: {
console: fakeConsole
}
}
);
log4js.configure({
appenders: { console: { type: 'console' } },
categories: { default: { appenders: ['console'], level: 'DEBUG' } }
});
log4js.getLogger().info('blah');
t.match(messages[0], /.*default.*blah/);
t.end();
});
batch.test('should output to console', (t) => {
const messages = [];
const fakeConsole = {

View File

@ -2,6 +2,7 @@
const test = require('tap').test;
const sandbox = require('sandboxed-module');
const hipchatAppender = require('../../lib/appenders/hipchat');
function setupLogging(category, options) {
const lastRequest = {};
@ -70,6 +71,11 @@ function setupLogging(category, options) {
}
test('HipChat appender', (batch) => {
batch.test('should export a configure function', (t) => {
t.type(hipchatAppender.configure, 'function');
t.end();
});
batch.test('when logging to HipChat v2 API', (t) => {
const customCallback = function () {
return 'works';

View File

@ -2,6 +2,7 @@
const test = require('tap').test;
const sandbox = require('sandboxed-module');
const appender = require('../../lib/appenders/logFaces-HTTP');
function setupLogging(category, options) {
const fakeAxios = {
@ -49,6 +50,11 @@ function setupLogging(category, options) {
}
test('logFaces appender', (batch) => {
batch.test('should export a configure function', (t) => {
t.type(appender.configure, 'function');
t.end();
});
batch.test('when using HTTP receivers', (t) => {
const setup = setupLogging('myCategory', {
application: 'LFS-HTTP',

View File

@ -2,6 +2,7 @@
const test = require('tap').test;
const sandbox = require('sandboxed-module');
const appender = require('../../lib/appenders/logFaces-UDP');
function setupLogging(category, options) {
const fakeDgram = {
@ -52,6 +53,11 @@ function setupLogging(category, options) {
}
test('logFaces appender', (batch) => {
batch.test('should export a configure function', (t) => {
t.type(appender.configure, 'function');
t.end();
});
batch.test('when using UDP receivers', (t) => {
const setup = setupLogging('udpCategory', {
application: 'LFS-UDP',

View File

@ -2,6 +2,7 @@
const test = require('tap').test;
const sandbox = require('sandboxed-module');
const appender = require('../../lib/appenders/logstashHTTP');
function setupLogging(category, options) {
const fakeAxios = {
@ -49,6 +50,11 @@ function setupLogging(category, options) {
}
test('logstashappender', (batch) => {
batch.test('should export a configure function', (t) => {
t.type(appender.configure, 'function');
t.end();
});
batch.test('when using HTTP receivers', (t) => {
const setup = setupLogging('myCategory', {
application: 'logstash-sample',

View File

@ -2,6 +2,7 @@
const test = require('tap').test;
const sandbox = require('sandboxed-module');
const appender = require('../../lib/appenders/logstashUDP');
function setupLogging(category, options) {
const udpSent = {};
@ -49,6 +50,11 @@ function setupLogging(category, options) {
}
test('logstashUDP appender', (batch) => {
batch.test('should export a configure function', (t) => {
t.type(appender.configure, 'function');
t.end();
});
batch.test('a UDP packet should be sent', (t) => {
const setup = setupLogging('myCategory', {
host: '127.0.0.1',

View File

@ -2,6 +2,7 @@
const test = require('tap').test;
const sandbox = require('sandboxed-module');
const appender = require('../../lib/appenders/rabbitmq');
function setupLogging(category, options) {
const fakeRabbitmq = {
@ -51,6 +52,11 @@ function setupLogging(category, options) {
}
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',

View File

@ -1,8 +1,8 @@
'use strict';
const test = require('tap').test;
// const log4js = require('../../lib/log4js');
const sandbox = require('sandboxed-module');
const appender = require('../../lib/appenders/redis');
function setupLogging(category, options) {
const fakeRedis = {
@ -56,6 +56,11 @@ function setupLogging(category, options) {
}
test('log4js redisAppender', (batch) => {
batch.test('should export a configure function', (t) => {
t.type(appender.configure, 'function');
t.end();
});
batch.test('redis setup', (t) => {
const result = setupLogging('redis setup', {
host: '123.123.123.123',