From ecb1543e2f60fe58145e46f758b83d48f118bc69 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 28 Apr 2016 05:17:54 -0300 Subject: [PATCH] Appender require fix error. Now mailgun is required on the configure function. This is to avoid not having __config object. Tests have been updated to adapt the changes --- lib/appenders/mailgun.js | 3 ++- test/mailgunAppender-test.js | 27 ++++++++++++++------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/appenders/mailgun.js b/lib/appenders/mailgun.js index d4fb549..44ded6e 100644 --- a/lib/appenders/mailgun.js +++ b/lib/appenders/mailgun.js @@ -19,7 +19,8 @@ function mailgunAppender(_config, _layout) { } mailgun.messages().send(data, function (error, body) { - console.log(body); + if (error != null) console.error("log4js.mailgunAppender - Error happened", error); + else console.log("Success", body); }) }; } diff --git a/test/mailgunAppender-test.js b/test/mailgunAppender-test.js index 851d4b2..38a31e7 100644 --- a/test/mailgunAppender-test.js +++ b/test/mailgunAppender-test.js @@ -10,18 +10,20 @@ function setupLogging(category, options) { var mailgunCredentials = { apiKey: options.apikey, domain: options.domain - } + }; - var fakeMailgun = { - messages: function () { - return { - config: options, - send: function (data, callback) { - msgs.push(data); - callback(false, {status:"OK"}); - } - }; - } + var fakeMailgun = function (conf) { + return { + messages: function () { + return { + config: options, + send: function (data, callback) { + msgs.push(data); + callback(false, {status:"OK"}); + } + }; + } + }; }; var fakeLayouts = { @@ -141,7 +143,7 @@ vows.describe('log4js mailgunAppender').addBatch({ setup.mailer.messages = function () { return { send: function (msg, cb) { - cb({message: "oh noes"}); + cb({msg: "log4js.mailgunAppender - Error happened"}, null); } }; } @@ -152,7 +154,6 @@ vows.describe('log4js mailgunAppender').addBatch({ 'should be logged to console': function (cons) { assert.equal(cons.errors.length, 1); assert.equal(cons.errors[0].msg, 'log4js.mailgunAppender - Error happened'); - assert.equal(cons.errors[0].value.message, 'oh noes'); } }, 'separate email for each event': {