Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

feat: upgrade winston #189

Merged
merged 4 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

All notable changes to the LaunchDarkly Server-Side SDK for Node.js will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org).

## [5.13.1] - 2020-04-24
### Changed:
- The `redis` package dependency has been updated to major version 3, which removes some deprecated usages (see [#184](https://github.com/launchdarkly/node-server-sdk/issues/184)) and adds support for `rediss:` URLs. This should not affect any application code even if the application is passing in a pre-built Redis client that was created with version 2.x, since the Redis methods that are used by the SDK have not changed.

### Fixed:
- If a proxy server was specified in the configuration, streaming connections still did not use the proxy. This bug was introduced in version 5.12.0. ([#186](https://github.com/launchdarkly/node-server-sdk/issues/186))
- The SDK could cause a crash if the application provided a configuration where `logger` was either not a logger at all (that is, some other object that did not have the methods defined in the `LDLogger` interface), or was a broken logger that could throw an exception while the SDK was trying to log an error. The former case (not a logger) is now treated as a severely invalid configuration, causing `LDClient.init()` to throw an exception just as it would if the SDK key were omitted. The latter (logger method throws an exception) is now handled by catching the exception and logging an error message to the _default_ console logger. (Thanks, [maxwellgerber](https://github.com/launchdarkly/node-server-sdk/pull/185)!)
- The Redis integration no longer calls `unref()` on the Redis client object after creating it. This was originally done to ensure that the SDK client would not prevent an application from exiting due to a still-open Redis connection, but that is no longer applicable since the application must close the SDK client anyway before exiting, which will cause the Redis client to be closed as well. The `unref()` call caused problems when running in Lambda, for unclear reasons. ([#76](https://github.com/launchdarkly/node-server-sdk/issues/76))

## [5.13.0] - 2020-04-07
### Added:
- Configuration option `streamInitialReconnectDelay`, which is the same as the recently-added `streamInitialReconnectDelayMillis` but measured in seconds instead of milliseconds; this makes it consistent with how durations are represented in other options.
Expand Down
12 changes: 8 additions & 4 deletions configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,17 @@ module.exports = (function() {
}

function fallbackLogger() {
return new winston.Logger({
const prefixFormat = winston.format(info => {
// eslint-disable-next-line no-param-reassign
info.message = '[LaunchDarkly] ' + (info.message ? info.message : '');
return info;
});

return winston.createLogger({
level: 'info',
transports: [
new winston.transports.Console({
formatter: function(options) {
return '[LaunchDarkly] ' + (options.message ? options.message : '');
},
format: prefixFormat(),
}),
],
});
Expand Down
2 changes: 1 addition & 1 deletion event_processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ function EventProcessor(sdkKey, config, errorReporter, diagnosticsManager) {
}
if (resp.statusCode > 204) {
const err = new errors.LDUnexpectedResponseError(
messages.httpErrorMessage(resp.statusCode, 'event posting', 'some events were dropped')
messages.httpErrorMessage({ status: resp.statusCode }, 'event posting', 'some events were dropped')
);
errorReporter && errorReporter(err);
if (!errors.isHttpErrorRecoverable(resp.statusCode)) {
Expand Down
2 changes: 1 addition & 1 deletion file_data_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function FileDataSource(options) {
let inited = false;

function defaultLogger() {
return new winston.Logger({
return winston.createLogger({
level: 'info',
transports: [new winston.transports.Console()],
});
Expand Down
14 changes: 5 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,16 +419,12 @@ function createProxyAgent(config) {
proxyAuth: config.proxyAuth,
},
};

const isTargetServerSecure =
(config.stream && (!config.streamUri || config.streamUri.startsWith('https'))) ||
(!config.stream && (!config.baseUri || config.baseUri.startsWith('https')));
if (config.proxyScheme === 'https') {
if (!config.baseUri || config.baseUri.startsWith('https')) {
return tunnel.httpsOverHttps(options);
} else {
return tunnel.httpOverHttps(options);
}
} else if (!config.baseUri || config.baseUri.startsWith('https')) {
return tunnel.httpsOverHttp(options);
return isTargetServerSecure ? tunnel.httpsOverHttps(options) : tunnel.httpOverHttps(options);
} else {
return tunnel.httpOverHttp(options);
return isTargetServerSecure ? tunnel.httpsOverHttp(options) : tunnel.httpOverHttp(options);
}
}
10 changes: 5 additions & 5 deletions messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ const errors = require('./errors');

exports.deprecated = (oldName, newName) => '"' + oldName + '" is deprecated, please use "' + newName + '"';

exports.httpErrorMessage = (status, context, retryMessage) => {
exports.httpErrorMessage = (err, context, retryMessage) => {
let desc;
if (status) {
desc = 'error ' + status + (status === 401 ? ' (invalid SDK key)' : '');
if (err.status) {
desc = 'error ' + err.status + (err.status === 401 ? ' (invalid SDK key)' : '');
} else {
desc = 'I/O error';
desc = 'I/O error (' + (err.message || err) + ')';
}
const action = errors.isHttpErrorRecoverable(status) ? retryMessage : 'giving up permanently';
const action = errors.isHttpErrorRecoverable(err.status) ? retryMessage : 'giving up permanently';
return 'Received ' + desc + ' for ' + context + ' - ' + action;
};

Expand Down
Loading