chore: deprecated the mailgun appender

This commit is contained in:
Gareth Jones 2018-04-19 08:06:31 +10:00
parent d9097e98a6
commit 7f65f51367
4 changed files with 14 additions and 34 deletions

View File

@ -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'`.

View File

@ -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'
}
});
```

View File

@ -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) {

View File

@ -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();