diff --git a/docs/appenders.md b/docs/appenders.md index 2a2de16..eceb162 100644 --- a/docs/appenders.md +++ b/docs/appenders.md @@ -28,7 +28,6 @@ The following appenders are included with log4js. Some require extra dependencie * [logFaces-UDP](logFaces-UDP.md) * [logLevelFilter](logLevelFilter.md) * [logstashHTTP](logstashHTTP.md) -* [mailgun](mailgun.md) * [multiFile](multiFile.md) * [multiprocess](multiprocess.md) * [recording](recording.md) @@ -47,6 +46,7 @@ The following appenders are supported by log4js, but will issue deprecation warn * [hipchat](https://github.com/log4js-node/hipchat) * [loggly](https://github.com/log4js-node/loggly) * [logstashUDP](https://github.com/log4js-node/logstashUDP) +* [mailgun](https://github.com/log4js-node/mailgun) For example, if you were previously using the gelf appender (`type: 'gelf'`) then you should add `@log4js-node/gelf` to your dependencies and change the type to `type: '@log4js-node/gelf'`. diff --git a/docs/mailgun.md b/docs/mailgun.md deleted file mode 100644 index bdf3cf1..0000000 --- a/docs/mailgun.md +++ /dev/null @@ -1,30 +0,0 @@ -# Mailgun Appender - -This appender uses the [mailgun](https://www.mailgun.com) service to send log messages as emails. It requires the [mailgun-js](https://www.npmjs.com/package/mailgun-js) package to be added to your dependencies. - -## Configuration - -* `type` - `mailgun` -* `apiKey` - `string` - your mailgun API key -* `domain` - `string` - your domain -* `from` - `string` -* `to` - `string` -* `subject` - `string` -* `layout` - `object` (optional, defaults to basicLayout) - see [layouts](layouts.md) - -The body of the email will be the result of applying the layout to the log event. Refer to the mailgun docs for how to obtain your API key. - -## Example - -```javascript -log4js.configure({ - appenders: { - type: 'mailgun', - apiKey: '123456abc', - domain: 'some.company', - from: 'logging@some.service', - to: 'important.bosses@some.company', - subject: 'Error: Developers Need To Be Fired' - } -}); -``` diff --git a/lib/appenders/mailgun.js b/lib/appenders/mailgun.js index 41ee19d..5fe2c17 100644 --- a/lib/appenders/mailgun.js +++ b/lib/appenders/mailgun.js @@ -1,5 +1,9 @@ 'use strict'; +/** + * This appender has been deprecated. + * Updates and bug fixes should be made against https://github.com/log4js-node/mailgun + */ const mailgunFactory = require('mailgun-js'); function mailgunAppender(config, layout) { @@ -8,7 +12,7 @@ function mailgunAppender(config, layout) { domain: config.domain }); - return (loggingEvent) => { + const appender = (loggingEvent) => { const data = { from: config.from, to: config.to, @@ -21,6 +25,11 @@ function mailgunAppender(config, layout) { if (error !== null) console.error('log4js.mailgunAppender - Error happened', error); }); }; + + // trigger a deprecation warning. + appender.deprecated = '@logj4s-node/mailgun'; + + return appender; } function configure(config, layouts) { diff --git a/test/tap/mailgunAppender-test.js b/test/tap/mailgunAppender-test.js index 248bd4a..0b5740b 100644 --- a/test/tap/mailgunAppender-test.js +++ b/test/tap/mailgunAppender-test.js @@ -147,8 +147,9 @@ test('log4js mailgunAppender', (batch) => { const cons = setup.console; t.test('should be logged to console', (assert) => { - assert.equal(cons.errors.length, 1); - assert.equal(cons.errors[0].msg, 'log4js.mailgunAppender - Error happened'); + assert.equal(cons.errors.length, 2); + // errors[0] is the deprecation warning + assert.equal(cons.errors[1].msg, 'log4js.mailgunAppender - Error happened'); assert.end(); }); t.end();