Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

logzio-nodejs

Package Overview
Dependencies
Maintainers
2
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

logzio-nodejs - npm Package Compare versions

Comparing version 0.3.4 to 0.3.5

16

lib/logzio-nodejs.js

@@ -24,4 +24,15 @@ var request = require('request');

this.numberOfRetries = options.numberOfRetries || 3;
/*
Callback method executed on each bulk of messages sent to logzio.
If the bulk failed, it will be called: callback(exception), otherwise upon
success it will called as callback()
*/
this.callback = options.callback || this._defaultCallback;
/*
* the read/write/connection timeout in milliseconds of the outgoing HTTP request
*/
this.timeout = options.timeout;
// build the url for logging

@@ -119,3 +130,3 @@ this.url = this.protocol + '://' + this.host + ':' + this.port + '?token=' + this.token;

mythis._debug("Bulk #"+bulk.id+" - Trying again in "+sleepTimeMs+ "[ms], attempt no. "+bulk.attemptNumber);
setInterval(function() {
setTimeout(function() {
mythis._send(bulk);

@@ -146,6 +157,7 @@ }, sleepTimeMs);

// In rare cases server is busy
if (err.code === 'ETIMEDOUT' || err.code == 'ECONNRESET'){
if (err.code === 'ETIMEDOUT' || err.code == 'ECONNRESET' || err.code === 'ESOCKETTIMEDOUT'){
if (bulk.attemptNumber >= mythis.numberOfRetries) {
callback(new Error("Failed after "+bulk.attemptNumber+" retries on error = "+err, err));
} else {
mythis._debug("Bulk #"+bulk.id+" - failed on error: "+err);
var sleepTimeMs = bulk.sleepUntilNextRetry;

@@ -152,0 +164,0 @@ bulk.sleepUntilNextRetry = bulk.sleepUntilNextRetry * 2;

4

package.json
{
"name": "logzio-nodejs",
"description": "A nodejs implementation for sending logs to Logz.IO cloud service",
"version": "0.3.4",
"version": "0.3.5",
"author": "Gilly Barr <gilly@logz.io>",

@@ -13,3 +13,3 @@ "contributors": [

"name": "Asaf Mesika",
"email": "amesika@logz.io"
"email": "asaf.mesika@gmail.com"
}

@@ -16,0 +16,0 @@ ],

@@ -42,7 +42,20 @@ # logzio-nodejs

## Update log
**0.3.5**
- Bug fix : upon retry (in case of network error), the message gets sent forever
## Update log
**0.3.4**
- Bug fix : `jsonToString()` was throwing an error in the catch()block
**0.3.2**
- Enhancement : Added option to attach extra fields to each log in a specific instance of the logger.
**0.3.1**
* Bug fix : When calling `log` with a string parameter, the object isn't constructed properly.
- Bug fix : When calling `log` with a string parameter, the object isn't constructed properly.
# Contibutors
- run `npm install` to install required dependencies
- run `npm test` to run unit tests

@@ -7,2 +7,5 @@ var sinon = require('sinon');

var dummyHost = "logz.io";
var nockHttpAddress = "http://"+dummyHost+":8070";
var createLogger = function(options) {

@@ -13,2 +16,3 @@ var myoptions = options;

myoptions.debug = true;
myoptions.host = dummyHost;
return logzioLogger.createLogger(myoptions);

@@ -156,2 +160,4 @@ };

var logger = createLogger({bufferSize:100, sendIntervalMs:10000, callback: shouldBeCalledTimes});
// These messages should be sent in 1 bulk 10 seconds from now (due to sendIntervalMs)
logger.log({messge:"hello there from test", testid:5});

@@ -161,2 +167,3 @@ logger.log({messge:"hello there from test2", testid:5});

// Schedule 100 msgs (buffer size) which should be sent in one bulk 11 seconds from start
setTimeout(function(){

@@ -168,10 +175,32 @@ for (var i = 0; i < 100; i++) {

});
});
describe('#retries', function () {
describe('#recover-after-server-fails-one-time', function () {
var errorAndThenSuccessScope;
var extraRequestScope;
before(function(done){
nock('http://listener.logz.io')
nock.cleanAll();
errorAndThenSuccessScope = nock(nockHttpAddress)
.post('/')
.delay(2000) // 2 seconds
.socketDelay(5000)
.query(true)
.once()
.reply(200, '')
// success
.post('/')
.socketDelay(0)
.query(true)
.once()
.reply(200, '');
extraRequestScope = nock(nockHttpAddress)
.filteringPath(function(path) {
return '/';
})
.post('/')
.once()
.reply(200, '')
done();

@@ -182,17 +211,27 @@ });

nock.restore();
nock.cleanAll();
done();
});
it('retry test', function (done) {
var logger = createLogger({bufferSize:3, callback: function(e) {
if (e) {
done();
it('Msgs are only sent once', function (done) {
// very small timeout so the first request will fail (nock setup this way above) and
// then second attempt will succeed
var logger = createLogger({bufferSize:1, sendIntervalMs:50000, timeout: 1000});
logger.log({messge:"hello there from test", testid:5});
setTimeout(function(){
if (!errorAndThenSuccessScope.isDone()) {
done(new Error('pending mocks: ' + errorAndThenSuccessScope.pendingMocks()));
} else {
done("failed");
if (extraRequestScope.isDone()) {
done(new Error("We don't expect another request"))
} else {
done();
}
}
} , timeout:1});
logger.log({messge:"hello there from test", testid:2});
logger.log({messge:"hello there from test2", testid:2});
logger.log({messge:"hello there from test3", testid:2});
}, 10000)
});
});

@@ -213,3 +252,3 @@

it('bad request', function (done) {
it('bad request test', function (done) {
var logger = createLogger({bufferSize:3, callback: function(err) {

@@ -216,0 +255,0 @@ if (err) {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc