diff --git a/README.md b/README.md index d82d2c6..43ca4cb 100644 --- a/README.md +++ b/README.md @@ -283,6 +283,8 @@ logger.info('end of log message'); logger.end(); ``` +The transport constructor accepts the same options as `createFluentSender`, including `enableReconnect`. + **NOTE** If you use `winston@2`, you can use `fluent-logger@2.7.0` or earlier. If you use `winston@3`, you can use `fluent-logger@2.8` or later. ### stream @@ -343,6 +345,11 @@ See [socket.setTimeout][2] Set the reconnect interval in milliseconds. If error occurs then reconnect after this interval. +**enableReconnect** + +Enable automatic reconnect. Default is `true`. +Set this to `false` to disable automatic reconnect. + [1]: https://nodejs.org/api/net.html#net_socket_connect_path_connectlistener [2]: https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback diff --git a/lib/index.d.ts b/lib/index.d.ts index 040fe69..fec17b8 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -16,6 +16,7 @@ declare namespace fluentLogger { timeout?: number; tls?: any; tlsOptions?: any; + enableReconnect?: boolean; reconnectInterval?: number; requireAckResponse?: boolean; ackResponseTimeout?: number; diff --git a/test/test.winston.js b/test/test.winston.js index 57ff820..762d706 100644 --- a/test/test.winston.js +++ b/test/test.winston.js @@ -2,6 +2,8 @@ /* globals describe, it */ /* eslint node/no-unpublished-require: ["error", {"allowModules": ["async", "chai", "winston"]}] */ const expect = require('chai').expect; +const fs = require('fs'); +const path = require('path'); const winstonSupport = require('../lib/winston'); const winston = require('winston'); const runServer = require('../lib/testHelper').runServer; @@ -41,5 +43,23 @@ describe('winston', () => { }, 1000); }); }); + + it('should honor enableReconnect', (done) => { + const transport = new winstonSupport('debug', { + enableReconnect: false, + reconnectInterval: 100 + }); + expect(transport.sender.enableReconnect).to.be.equal(false); + expect(transport.sender._eventEmitter.listeners('error').length).to.be.equal(0); + done(); + }); + }); + + describe('types', () => { + it('should include enableReconnect in Options', (done) => { + const dts = fs.readFileSync(path.join(__dirname, '../lib/index.d.ts'), 'utf8'); + expect(dts).to.match(/interface Options \{[\s\S]*enableReconnect\?:\s*boolean/); + done(); + }); }); });