logzio-nodejs
Advanced tools
Comparing version 2.0.4 to 2.1.4
@@ -21,3 +21,2 @@ const logzioLogger = require('./index'); | ||
logger.log('some testing'); | ||
@@ -24,0 +23,0 @@ |
@@ -1,2 +0,1 @@ | ||
const request = require('request-promise'); | ||
const stringifySafe = require('json-stringify-safe'); | ||
@@ -6,3 +5,5 @@ const assign = require('lodash.assign'); | ||
const zlib = require('zlib'); | ||
const axiosInstance = require('./axiosInstance'); | ||
const nanoSecDigits = 9; | ||
@@ -82,3 +83,14 @@ | ||
this._setProtocol(port); | ||
this.url = `${this.protocol}://${this.host}:${this.port}?token=${this.token}`; | ||
this.axiosInstance = axiosInstance; | ||
this.axiosInstance.defaults.headers.post = { | ||
Host: this.host, | ||
Accept: '*/*', | ||
'Content-Type': 'text/plain', | ||
...(this.setUserAgent ? { 'user-agent': USER_AGENT } : {}), | ||
...(this.compress ? { 'content-encoding': 'gzip' } : {}), | ||
}; | ||
/* | ||
@@ -97,3 +109,2 @@ Callback method executed on each bulk of messages sent to logzio. | ||
// build the url for logging | ||
this.url = `${this.protocol}://${this.host}:${this.port}?token=${this.token}`; | ||
@@ -260,14 +271,5 @@ this.messages = []; | ||
const body = messagesToBody(bulk.msgs); | ||
const options = { | ||
uri: this.url, | ||
headers: { | ||
host: this.host, | ||
accept: '*/*', | ||
'content-type': 'text/plain', | ||
...(this.setUserAgent ? { 'user-agent': USER_AGENT } : {}), | ||
}, | ||
}; | ||
if (typeof this.timeout !== 'undefined') { | ||
options.timeout = this.timeout; | ||
this.axiosInstance.defaults.timeout = this.timeout; | ||
} | ||
@@ -278,3 +280,2 @@ | ||
if (this.compress) { | ||
options.headers['content-encoding'] = 'gzip'; | ||
return zlibPromised(body); | ||
@@ -285,10 +286,9 @@ } | ||
.then((finalBody) => { | ||
options.body = finalBody; | ||
this._tryToSend(options, bulk); | ||
this._tryToSend(finalBody, bulk); | ||
}); | ||
} | ||
_tryToSend(options, bulk) { | ||
this._debug(`Sending bulk of ${bulk.msgs.length} logs`) | ||
return request.post(options) | ||
_tryToSend(body, bulk) { | ||
this._debug(`Sending bulk of ${bulk.msgs.length} logs`); | ||
return this.axiosInstance.post(this.url, body) | ||
.then(() => { | ||
@@ -300,3 +300,3 @@ this._debug(`Bulk #${bulk.id} - sent successfully`); | ||
// In rare cases server is busy | ||
const errorCode = err.cause && err.cause.code; | ||
const errorCode = err.code; | ||
if (UNAVAILABLE_CODES.includes(errorCode)) { | ||
@@ -303,0 +303,0 @@ if (bulk.attemptNumber >= this.numberOfRetries) { |
{ | ||
"name": "logzio-nodejs", | ||
"description": "A nodejs implementation for sending logs to Logz.IO cloud service Copy of logzio-nodejs", | ||
"version": "2.0.4", | ||
"version": "2.1.4", | ||
"author": "Gilly Barr <gilly@logz.io>", | ||
@@ -27,6 +27,6 @@ "contributors": [ | ||
}, | ||
{ | ||
"name": "Anton Kolomiiets", | ||
"email": "resdenia@gmail.com" | ||
} | ||
{ | ||
"name": "Anton Kolomiiets", | ||
"email": "resdenia@gmail.com" | ||
} | ||
], | ||
@@ -45,7 +45,6 @@ "repository": { | ||
"dependencies": { | ||
"axios": "0.27.2", | ||
"json-stringify-safe": "5.0.1", | ||
"lodash.assign": "4.2.0", | ||
"moment": "2.29.2", | ||
"request": "^2.88.0", | ||
"request-promise": "^4.2.4" | ||
"moment": "2.29.4" | ||
}, | ||
@@ -52,0 +51,0 @@ "devDependencies": { |
@@ -63,2 +63,5 @@ ![Build Status](https://travis-ci.org/logzio/logzio-nodejs.svg?branch=master) | ||
## Update log | ||
**2.1.4** | ||
- Replace from request to axios | ||
**2.0.4** | ||
@@ -65,0 +68,0 @@ - Add parameter to manage User-agent |
const sinon = require('sinon'); | ||
const request = require('request-promise'); | ||
const nock = require('nock'); | ||
@@ -9,3 +8,6 @@ const assert = require('assert'); | ||
const hrtimemock = require('hrtimemock'); | ||
const axiosInstance = require('../lib/axiosInstance.js'); | ||
axiosInstance.defaults.adapter = require('axios/lib/adapters/http'); | ||
const dummyHost = 'logz.io'; | ||
@@ -32,3 +34,2 @@ const nockHttpAddress = `http://${dummyHost}:8070`; | ||
}; | ||
describe('logger', () => { | ||
@@ -38,3 +39,3 @@ describe('logs a single line', () => { | ||
sinon | ||
.stub(request, 'post') | ||
.stub(axiosInstance, 'post') | ||
.resolves({ | ||
@@ -47,3 +48,3 @@ statusCode: 200, | ||
afterAll((done) => { | ||
request.post.restore(); | ||
axiosInstance.post.restore(); | ||
done(); | ||
@@ -78,3 +79,3 @@ }); | ||
function onDone() { | ||
assert.equal(logger._tryToSend.getCall(0).args[0].headers['user-agent'], undefined); | ||
assert.equal(axiosInstance.defaults.headers.common['user-agent'], undefined); | ||
logger._tryToSend.restore(); | ||
@@ -182,4 +183,4 @@ logger.close(); | ||
function onDone() { | ||
assert.equal(logger._tryToSend.getCall(0).args[0].headers['content-encoding'], 'gzip'); | ||
const unzipBody = JSON.parse(zlib.gunzipSync(logger._tryToSend.getCall(0).args[0].body)); | ||
assert.equal(axiosInstance.defaults.headers.post['content-encoding'], 'gzip'); | ||
const unzipBody = JSON.parse(zlib.gunzipSync(logger._tryToSend.getCall(0).args[0])); | ||
assert.equal(unzipBody.message, logMsg.message); | ||
@@ -294,3 +295,3 @@ assert.equal(unzipBody.extraField1, extraField1); | ||
sinon | ||
.stub(request, 'post') | ||
.stub(axiosInstance, 'post') | ||
.resolves({ | ||
@@ -303,3 +304,3 @@ statusCode: 200, | ||
afterAll((done) => { | ||
request.post.restore(); | ||
axiosInstance.post.restore(); | ||
done(); | ||
@@ -349,3 +350,3 @@ }); | ||
sinon | ||
.stub(request, 'post') | ||
.stub(axiosInstance, 'post') | ||
.resolves({ | ||
@@ -358,3 +359,3 @@ statusCode: 200, | ||
afterAll((done) => { | ||
request.post.restore(); | ||
axiosInstance.post.restore(); | ||
done(); | ||
@@ -382,3 +383,3 @@ }); | ||
sinon | ||
.stub(request, 'post') | ||
.stub(axiosInstance, 'post') | ||
.resolves({ | ||
@@ -391,3 +392,3 @@ statusCode: 200, | ||
afterAll((done) => { | ||
request.post.restore(); | ||
axiosInstance.post.restore(); | ||
done(); | ||
@@ -486,3 +487,3 @@ }); | ||
afterEach((done) => { | ||
request.post.restore(); | ||
axiosInstance.post.restore(); | ||
done(); | ||
@@ -493,3 +494,3 @@ }); | ||
sinon | ||
.stub(request, 'post') | ||
.stub(axiosInstance, 'post') | ||
.rejects({ | ||
@@ -520,3 +521,3 @@ statusCode: 400, | ||
sinon | ||
.stub(request, 'post') | ||
.stub(axiosInstance, 'post') | ||
.rejects({ | ||
@@ -523,0 +524,0 @@ statusCode: 400, |
67671
4
23
898
159
+ Addedaxios@0.27.2
+ Addedaxios@0.27.2(transitive)
+ Addedfollow-redirects@1.15.6(transitive)
+ Addedform-data@4.0.0(transitive)
+ Addedmoment@2.29.4(transitive)
- Removedrequest@^2.88.0
- Removedrequest-promise@^4.2.4
- Removedajv@6.12.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.12.0(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedbluebird@3.7.2(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedlodash@4.17.21(transitive)
- Removedmoment@2.29.2(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.9.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedrequest-promise@4.2.6(transitive)
- Removedrequest-promise-core@1.1.4(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedstealthy-require@1.1.1(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)
Updatedmoment@2.29.4