Skip to content

Commit 148f056

Browse files
committed
resolve filelogger err and add retries
1 parent 0341668 commit 148f056

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

bin/helpers/logger.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ const winston = require('winston'),
22
fs = require("fs"),
33
path = require("path");
44

5-
const { format } = winston;
6-
// const { format } = require("logform");
7-
85
const logDir = "log"; // directory path for logs
96
if (!fs.existsSync(logDir)) {
107
// Create the directory if it does not exist

bin/helpers/usageReporting.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
2-
const cp = require('child_process'),
3-
os = require('os'),
4-
request = require('request'),
2+
const cp = require("child_process"),
3+
os = require("os"),
4+
request = require("requestretry"),
55
fs = require('fs'),
66
path = require('path');
77

@@ -188,19 +188,25 @@ function send(args) {
188188
url: config.usageReportingUrl,
189189
body: payload,
190190
json: true,
191+
maxAttempts: 10, // (default) try 3 times
192+
retryDelay: 2000, // (default) wait for 2s before trying again
193+
retrySrategy: request.RetryStrategies.HTTPOrNetworkError, // (default) retry on 5xx or network errors
191194
};
192195

193-
fileLogger.info(`Sending ${payload} to ${config.usageReportingUrl}`);
196+
fileLogger.info(`Sending ${JSON.stringify(payload)} to ${config.usageReportingUrl}`);
194197
request(options, function (error, res, body) {
195198
if (error) {
196199
//write err response to file
197-
fileLogger.err(JSON.stringify(error));
200+
fileLogger.error(JSON.stringify(error));
198201
return;
199202
}
200-
// write response and body to file
201-
fileLogger.info(
202-
`statusCode: ${res.statusCode}, body: ${JSON.stringify(body)}`
203-
);
203+
// write response file
204+
let response = {
205+
attempts: res.attempts,
206+
statusCode: res.statusCode,
207+
body: body
208+
};
209+
fileLogger.info(`${JSON.stringify(response)}`);
204210
});
205211
}
206212

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
"fs-extra": "^8.1.0",
1717
"mkdirp": "^1.0.3",
1818
"request": "^2.88.0",
19-
"yargs": "^14.2.2",
20-
"winston": "^2.3.1"
19+
"requestretry": "^4.1.0",
20+
"winston": "^2.3.1",
21+
"yargs": "^14.2.2"
2122
},
2223
"repository": {
2324
"type": "git",

0 commit comments

Comments
 (0)