Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new flag for network errors #39

Merged
merged 1 commit into from Jul 5, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Add new flag for network errors

  • Loading branch information
Shweta Jain
Shweta Jain committed Jun 27, 2018
commit 80ea5d715c6a5c543294c4809c9ebd457ff7e45c
@@ -77,6 +77,7 @@ var Loggly = exports.Loggly = function (options) {
this.useTagHeader = 'useTagHeader' in options ? options.useTagHeader : true;
this.isBulk = options.isBulk || false;
this.bufferOptions = options.bufferOptions || {size: 500, retriesInMilliSeconds: 30 * 1000};
this.networkErrorsOnConsole = options.networkErrorsOnConsole || false;
//
// Set the tags on this instance.
//
@@ -153,6 +154,7 @@ Loggly.prototype.log = function (msg, tags, callback) {
proxy: this.proxy,
isBulk: this.isBulk,
bufferOptions: this.bufferOptions,
networkErrorsOnConsole: this.networkErrorsOnConsole,
headers: {
host: this.host,
accept: '*/*',
@@ -90,7 +90,8 @@ common.loggly = function () {
proxy,
isBulk,
uri,
bufferOptions;
bufferOptions,
networkErrorsOnConsole;

//
// Now that we've popped off the two callbacks
@@ -113,6 +114,7 @@ common.loggly = function () {
headers = args[0].headers;
proxy = args[0].proxy;
bufferOptions = args[0].bufferOptions;
networkErrorsOnConsole = args[0].networkErrorsOnConsole;
}
}
else if (args.length === 2) {
@@ -201,7 +203,7 @@ common.loggly = function () {
return onError((new Error('Loggly Error (' + responseCode + '): ' + httpStatusCode.badToken.message)));
}
if (responseCode === httpStatusCode.success.code && input.attemptNumber >= eventRetried) {
console.log('log #' + input.id + ' sent successfully after ' + input.attemptNumber + ' retries');
if (networkErrorsOnConsole) console.log('log #' + input.id + ' sent successfully after ' + input.attemptNumber + ' retries');
}
if (responseCode === httpStatusCode.success.code) {
success(res, body);
@@ -239,7 +241,7 @@ common.loggly = function () {
return onError((new Error('Loggly Error (' + responseCode + '): ' + httpStatusCode.badToken.message)));
}
if (responseCode === httpStatusCode.success.code && bulk.attemptNumber >= eventRetried) {
console.log('log #' + bulk.id + ' sent successfully after ' + bulk.attemptNumber + ' retries');
if (networkErrorsOnConsole) console.log('log #' + bulk.id + ' sent successfully after ' + bulk.attemptNumber + ' retries');
}
if (responseCode === httpStatusCode.success.code) {
success(res, body);
@@ -285,22 +287,22 @@ common.loggly = function () {
//
function retryOnError(mode, response) {
function tryAgainIn(sleepTimeMs) {
console.log('log #' + mode.id + ' - Trying again in ' + sleepTimeMs + '[ms], attempt no. ' + mode.attemptNumber);
if (networkErrorsOnConsole) console.log('log #' + mode.id + ' - Trying again in ' + sleepTimeMs + '[ms], attempt no. ' + mode.attemptNumber);
setTimeout(function () {
isBulk ? sendBulkLogs(mode) : sendInputLogs(mode);
}, sleepTimeMs);
}
if (mode.attemptNumber >= numberOfRetries) {
if (response.code) {
console.error('Failed log #' + mode.id + ' after ' + mode.attemptNumber + ' retries on error = ' + response, response);
if (networkErrorsOnConsole) console.error('Failed log #' + mode.id + ' after ' + mode.attemptNumber + ' retries on error = ' + response, response);
} else {
console.error('Failed log #' + mode.id + ' after ' + mode.attemptNumber + ' retries on error = ' + response.statusCode + ' ' + response.statusMessage);
if (networkErrorsOnConsole) console.error('Failed log #' + mode.id + ' after ' + mode.attemptNumber + ' retries on error = ' + response.statusCode + ' ' + response.statusMessage);
}
} else {
if (response.code) {
console.log('log #' + mode.id + ' - failed on error: ' + response);
if (networkErrorsOnConsole) console.log('log #' + mode.id + ' - failed on error: ' + response);
} else {
console.log('log #' + mode.id + ' - failed on error: ' + response.statusCode + ' ' + response.statusMessage);
if (networkErrorsOnConsole) console.log('log #' + mode.id + ' - failed on error: ' + response.statusCode + ' ' + response.statusMessage);
}
sleepTimeMs = mode.sleepUntilNextRetry;
mode.sleepUntilNextRetry = mode.sleepUntilNextRetry * 2;
@@ -1,7 +1,7 @@
{
"name": "node-loggly-bulk",
"description": "A client implementation for Loggly cloud Logging-as-a-Service API",
"version": "2.2.2",
"version": "2.2.3",
"author": "Charlie Robbins <charlie.robbins@gmail.com>",
"repository": {
"type": "git",
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.