Merge pull request #725 from log4js-node/deprecate-redis

Deprecate Redis appender
This commit is contained in:
Gareth Jones 2018-06-05 08:30:37 +10:00 committed by GitHub
commit 581f940153
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 15 additions and 35 deletions

View File

@ -31,7 +31,6 @@ The following appenders are included with log4js. Some require extra dependencie
* [multiFile](multiFile.md)
* [multiprocess](multiprocess.md)
* [recording](recording.md)
* [redis](redis.md)
* [slack](slack.md)
* [stderr](stderr.md)
* [stdout](stdout.md)
@ -46,6 +45,7 @@ The following appenders are supported by log4js, but will issue deprecation warn
* [loggly](https://github.com/log4js-node/loggly)
* [logstashUDP](https://github.com/log4js-node/logstashUDP)
* [mailgun](https://github.com/log4js-node/mailgun)
* [redis](https://github.com/log4js-node/redis)
* [smtp](https://github.com/log4js-node/smtp)
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,27 +0,0 @@
# Redis Appender
Stores log events in a [Redis](https://redis.io) database. You will need to include the [redis](https://www.npmjs.com/package/redis) package in your application's dependencies to use this appender.
## Configuration
* `type` - `redis`
* `host` - `string` (optional, defaults to `127.0.0.1`) - the location of the redis server
* `port` - `integer` (optional, defaults to `6379`) - the port the redis server is listening on
* `pass` - `string` (optional) - password to use when authenticating connection to redis
* `channel` - `string` - the redis channel that log events will be published to
* `layout` - `object` (optional, defaults to `messagePassThroughLayout`) - the layout to use for log events (see [layouts](layouts.md)).
The appender will use the Redis PUBLISH command to send the log event messages to the channel.
## Example
```javascript
log4js.configure({
appenders: {
redis: { type: 'redis', channel: 'logs' }
},
categories: { default: { appenders: ['redis'], level: 'info' } }
});
```
This configuration will publish log messages to the `logs` channel on `127.0.0.1:6379`.

View File

@ -14,7 +14,7 @@ log4js.configure({
alwaysIncludePattern: false
},
db: {
type: 'redis',
type: '@log4js-node/redis',
host: '127.0.0.1',
port: 6379,
pass: '',

View File

@ -9,7 +9,7 @@ log4js.configure({
type: 'console'
},
mail: {
type: 'smtp',
type: '@log4js-node/smtp',
recipients: 'logfilerecipient@logging.com',
sendInterval: 5,
transport: 'SMTP',

View File

@ -1,5 +1,9 @@
'use strict';
/**
* This appender has been deprecated, and will be removed in version 3.
* Any bug fixes or improvements should be made against @log4js-node/redis
*/
const redis = require('redis');
const util = require('util');
@ -29,6 +33,9 @@ function redisAppender(config, layout) {
if (cb) cb();
};
// trigger a deprecation warning.
appender.deprecated = '@logj4s-node/redis';
return appender;
}

View File

@ -126,11 +126,11 @@ test('multiprocess appender crash (worker)', (t) => {
worker.on('message', (m) => {
if (m === 'worker is done') {
worker.kill();
setTimeout(() => {
worker.kill();
t.equal(messages[0], 'Logging from worker');
log4jsWithFakeConsole.shutdown(() => t.end());
}, 500);
}, 100);
}
});
});

View File

@ -124,13 +124,13 @@ test('log4js redisAppender', (batch) => {
setup.fakeRedis.publishCb('oh no, error on publish');
t.test('should go to the console', (assert) => {
assert.equal(setup.fakeConsole.errors.length, 2);
assert.equal(setup.fakeConsole.errors.length, 3);
assert.equal(
setup.fakeConsole.errors[0],
setup.fakeConsole.errors[1],
'log4js.redisAppender - 127.0.0.1:6379 Error: \'oh no, error on connect\''
);
assert.equal(
setup.fakeConsole.errors[1],
setup.fakeConsole.errors[2],
'log4js.redisAppender - 127.0.0.1:6379 Error: \'oh no, error on publish\''
);
assert.end();