Socket
Socket
Sign inDemoInstall

node-loggly-bulk

Package Overview
Dependencies
11
Maintainers
4
Versions
24
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.1 to 4.0.1

test/logs.test.js

5

lib/loggly.js

@@ -18,6 +18,1 @@ /*

loggly.Loggly = require('./loggly/client').Loggly;
//
// Export Resources for node-loggly
//
loggly.Search = require('./loggly/search').Search;

49

lib/loggly/client.js

@@ -17,3 +17,2 @@ /*

loggly = require('../loggly'),
Search = require('./search').Search,
stringifySafe = require('json-stringify-safe');

@@ -198,4 +197,4 @@

if(body && res.statusCode.toString() === '200'){
var result = JSON.parse(body);
if(body && res.status.toString() === '200'){
var result = body;
self.emit('log', result);

@@ -207,3 +206,3 @@ if (callback) {

else
console.log('Error Code- ' + res.statusCode + ' "' + res.statusMessage + '"');
console.log('Error Code- ' + res.status + ' "' + res.statusMessage + '"');
}

@@ -246,44 +245,2 @@ catch (ex) {

//
// ### function customer (callback)
// ### @callback {function} Continuation to respond to.
// Retrieves the customer information from the Loggly API:
// - http://www.loggly.com/docs/api-account-info/
//
Loggly.prototype.customer = function (callback) {
common.loggly({
uri: this.logglyUrl('customer'),
auth: this.auth
}, callback, function (res, body) {
var customer;
try { customer = JSON.parse(body) }
catch (ex) { return callback(ex) }
callback(null, customer);
});
};
//
// function search (query, callback)
// Returns a new search object which can be chained
// with options or called directly if @callback is passed
// initially.
//
// Sample Usage:
//
// client.search('404', function () { /* ... */ })
// .on('rsid', function (rsid) { /* ... */ })
//
// client.search({ query: '404', rows: 100 })
// .on('rsid', function (rsid) { /* ... */ })
// .run(function () { /* ... */ });
//
Loggly.prototype.search = function (query, callback) {
var options = typeof query === 'string'
? { query: query }
: query;
options.callback = callback;
return new Search(options, this);
};
//
// function logglyUrl ([path, to, resource])

@@ -290,0 +247,0 @@ // Helper method that concats the string params into a url

@@ -56,3 +56,3 @@ /*

var request = require('request');
var axios = require('axios');
var common = exports;

@@ -151,3 +151,4 @@

headers: isBulk ? {} : headers || {}, // Set headers empty for bulk
proxy: proxy
proxy: proxy,
data: requestBody,
};

@@ -158,5 +159,6 @@

if (auth) {
// eslint-disable-next-line no-undef
// eslint-disable-next-line no-undef
requestOptions.headers.authorization = 'Basic ' + Buffer.from(auth.username + ':' + auth.password, 'base64');
}
function popMsgsAndSend() {

@@ -194,32 +196,40 @@ if (isBulk) {

try {
request(requestOptions, function (err, res, body) {
if (err) {
// In rare cases server is busy
if (err.code === 'ETIMEDOUT' || err.code === 'ECONNRESET' || err.code === 'ESOCKETTIMEDOUT' || err.code === 'ECONNABORTED') {
retryOnError(input, err);
axios(uri, requestOptions).then(function(res){
responseCode = res.status;
const body = res.data;
if (responseCode === httpStatusCode.badToken.code) {
isValidToken = false;
return onError((new Error('Loggly Error (' + responseCode + '): ' + httpStatusCode.badToken.message)));
}
if (responseCode === httpStatusCode.success.code && input.attemptNumber >= eventRetried) {
// eslint-disable-next-line no-undef
if (networkErrorsOnConsole) console.log('log #' + input.id + ' sent successfully after ' + input.attemptNumber + ' retries');
}
if (responseCode === httpStatusCode.success.code) {
success(res, body);
} else {
return onError(err);
retryOnError(input, res);
}
} else {
responseCode = res.statusCode;
if (responseCode === httpStatusCode.badToken.code) {
isValidToken = false;
return onError((new Error('Loggly Error (' + responseCode + '): ' + httpStatusCode.badToken.message)));
}
if (responseCode === httpStatusCode.success.code && input.attemptNumber >= eventRetried) {
// eslint-disable-next-line no-undef
if (networkErrorsOnConsole) console.log('log #' + input.id + ' sent successfully after ' + input.attemptNumber + ' retries');
}
if (responseCode === httpStatusCode.success.code) {
success(res, body);
} else {
retryOnError(input, res);
}
}
});
}
catch (ex) {
})
.catch(function(err) {
return handleRequestError(input, err);
});
} catch (ex) {
onError(ex);
}
}
function handleRequestError(input, err) {
// In rare cases server is busy
if(err.cause && err.cause.code) {
const code = err.cause.code;
if (code === 'ETIMEDOUT' || code === 'ECONNRESET' || code === 'ESOCKETTIMEDOUT' || code === 'ECONNABORTED') {
retryOnError(input, err);
}
} else {
return onError(err);
}
}
function sendBulkLogs(bulk) {

@@ -235,25 +245,19 @@ //

// eslint-disable-next-line no-unused-vars
request(requestOptions, function (err, res, body) {
if (err) {
// In rare cases server is busy
if (err.code === 'ETIMEDOUT' || err.code === 'ECONNRESET' || err.code === 'ESOCKETTIMEDOUT' || err.code === 'ECONNABORTED') {
retryOnError(bulk, err);
} else {
return onError(err);
axios(uri, requestOptions).then(function(res){
const responseCode = res.status;
if (responseCode === httpStatusCode.badToken.code) {
isValidToken = false;
return onError((new Error('Loggly Error (' + responseCode + '): ' + httpStatusCode.badToken.message)));
}
} else {
responseCode = res.statusCode;
if (responseCode === httpStatusCode.badToken.code) {
isValidToken = false;
return onError((new Error('Loggly Error (' + responseCode + '): ' + httpStatusCode.badToken.message)));
}
if (responseCode === httpStatusCode.success.code && bulk.attemptNumber >= eventRetried) {
// eslint-disable-next-line no-undef
if (networkErrorsOnConsole) console.log('log #' + bulk.id + ' sent successfully after ' + bulk.attemptNumber + ' retries');
}
if (responseCode !== httpStatusCode.success.code) {
retryOnError(bulk, res);
}
if (responseCode === httpStatusCode.success.code && bulk.attemptNumber >= eventRetried) {
// eslint-disable-next-line no-undef
if (networkErrorsOnConsole) console.log('log #' + bulk.id + ' sent successfully after ' + bulk.attemptNumber + ' retries');
}
});
if (responseCode !== httpStatusCode.success.code) {
retryOnError(bulk, res);
}
})
.catch(function(e) {
return handleRequestError(bulk, e);
})
}

@@ -309,3 +313,3 @@ catch (ex) {

if (mode.attemptNumber >= numberOfRetries) {
if (response.code) {
if (response.cause) {
// eslint-disable-next-line no-undef

@@ -318,3 +322,3 @@ if (networkErrorsOnConsole) console.error('Failed log #' + mode.id + ' after ' + mode.attemptNumber + ' retries on error = ' + response, response);

} else {
if (response.code) {
if (response.cause) {
// eslint-disable-next-line no-undef

@@ -358,12 +362,14 @@ if (networkErrorsOnConsole) console.log('log #' + mode.id + ' - failed on error: ' + response);

// eslint-disable-next-line no-unused-vars
request(requestOptionsForBufferedLogs, function (err, res, body) {
if(err) return;
// eslint-disable-next-line no-undef
statusCode = res.statusCode;
// eslint-disable-next-line no-undef
if(statusCode === httpStatusCode.success.code) {
arrBufferedMsg.splice(0, logsInBunch);
sendBufferdLogstoLoggly();
}
});
axios(uri, requestOptionsForBufferedLogs)
.then(function(res) {
var statusCode = res.status;
// eslint-disable-next-line no-undef
if(statusCode === httpStatusCode.success.code) {
arrBufferedMsg.splice(0, logsInBunch);
sendBufferdLogstoLoggly();
}
})
.catch(function() {
return;
})
requestOptionsForBufferedLogs.body = '';

@@ -370,0 +376,0 @@ }

{
"name": "node-loggly-bulk",
"description": "A client implementation for Loggly cloud Logging-as-a-Service API",
"version": "3.0.1",
"version": "4.0.1",
"author": "Charlie Robbins <charlie.robbins@gmail.com>",

@@ -17,4 +17,4 @@ "repository": {

"dependencies": {
"request": ">=2.88.2 <3.0.0",
"moment": "^2.18.1",
"axios": "1.3.4",
"moment": "2.29.4",
"json-stringify-safe": "5.0.x"

@@ -24,4 +24,3 @@ },

"eslint": "^8.2.0",
"nock": "^13.0.11",
"vows": "0.8.3"
"jest": "29.5.0"
},

@@ -31,4 +30,3 @@ "main": "./lib/loggly",

"lint": "eslint --max-warnings 0 --ext lib/**/*.js lib/*.js --fix",
"test": "vows test/*-test.js --spec",
"test-as-mock": "vows test-as-mock/*-test.js --spec"
"test": "jest"
},

@@ -35,0 +33,0 @@ "license": "MIT",

@@ -11,3 +11,3 @@ # node-loggly-bulk

The `node-loggly-bulk` library is compliant with the [Loggly API][api]. Using `node-loggly-bulk` is easy for a variety of scenarios: logging, working with devices and inputs, searching, and facet searching.
The `node-loggly-bulk` library is compliant with the [Loggly API][api]. Using `node-loggly-bulk` you can send logs to Loggly.

@@ -23,6 +23,2 @@ ### Getting Started

subdomain: "your-subdomain",
auth: {
username: "your-username",
password: "your-password"
},
//

@@ -64,3 +60,3 @@ // Optional: Tag to send with EVERY log message

### Logging Shallow JSON Objects as a String
In addition to logging pure strings it is also possible to pass shallow JSON object literals (i.e. no nested objects) to client.log(..) or input.log(..) methods, which will get converted into the [Loggly recommended string representation][sending-data]. So
In addition to logging pure strings, it is also possible to pass shallow JSON object literals (i.e. no nested objects) to client.log(..) or input.log(..) methods, which will get converted into the [Loggly recommended string representation][sending-data]. So

@@ -88,7 +84,4 @@ ``` js

var config = {
token: 'token',
subdomain: "your-subdomain",
auth: {
username: "your-username",
password: "your-password"
},
json: true

@@ -126,28 +119,2 @@ };

### Searching
[Searching][search-api] with node-loggly-bulk is easy. All you have to do is use the search() method defined on each Loggly client:
``` js
var util = require('util');
client.search('404', function (err, results) {
// Inspect the result set
console.dir(results.events);
});
```
The search() method can also take an Object parameter that allows you to set additional search parameters such as: rows, from, until, etc.
``` js
var util = require('util');
client.search({ query: '404', rows: 10 })
.run(function (err, results) {
// Inspect the result set
console.dir(results.events);
});
```
See the [Loggly search guide][search] for more details on how to effectively search through your Loggly logs.
## Installation

@@ -167,26 +134,7 @@

### Run Tests by sending events to your Loggly Account
All of the node-loggly-bulk tests are written in [vows][vows], and cover all of the use cases described above. You will need to add your Loggly username, password, subdomain, and your loggly token to test/config.json before running tests.
``` js
{
"token": "your-really-long-token-you-got-when-you-created-an-http-input",
"subdomain": "your-subdomain",
"auth": {
"username": "your-username",
"password": "your-password"
}
}
``` bash
$ npm run test
```
Once you have valid Loggly credentials you can run tests with [vows][vows]:
``` bash
$ npm test
```
### Run Tests with Mock HTTP Request
To mock the HTTP requests and run test cases in your local machine you can run the following command
```bash
$ npm run test-as-mock
```

@@ -193,0 +141,0 @@ #### Author: [Charlie Robbins](http://www.github.com/indexzero)

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