Socket
Socket
Sign inDemoInstall

logzio-nodejs

Package Overview
Dependencies
11
Maintainers
6
Versions
51
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.4 to 2.1.4

lib/axiosInstance.js

1

example.js

@@ -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,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc