New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bunyan-loggly

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bunyan-loggly - npm Package Compare versions

Comparing version 0.0.5 to 1.0.0

.jshintignore

92

index.js

@@ -0,64 +1,68 @@

var loggly = require('loggly');
var loggly = require('loggly'),
util = require('util');
function Bunyan2Loggly(logglyConfig, bufferLength, bufferTimeout){
if(!logglyConfig || !logglyConfig.token || !logglyConfig.subdomain){
throw new Error('bunyan-loggly requires a config object with token and subdomain');
}
function Bunyan2Loggly (logglyConfig, buffer) {
logglyConfig.json = true;
this.logglyConfig = logglyConfig || {};
this.logglyClient = loggly.createClient(logglyConfig);
// define the log as being json (because bunyan is a json logger)
this.logglyConfig.json = true;
// define the buffer count, unless one has already been defined
this.buffer = buffer || 1;
this._buffer = [];
// add the https tag by default, just to make the loggly source setup work as expect
this.logglyConfig.tags = this.logglyConfig.tags || [];
this.logglyConfig.tags.push('https');
// create the client
this.client = loggly.createClient(logglyConfig);
this._buffer = [];
this.bufferLength = bufferLength || 1;
this.bufferTimeout = bufferTimeout;
}
Bunyan2Loggly.prototype.write = function(rec) {
Bunyan2Loggly.prototype.write = function(data){
if (typeof data !== 'object') {
throw new Error('bunyan-loggly requires a raw stream. Please define the type as raw when setting up the bunyan stream.');
}
if (typeof rec !== 'object' && !Array.isArray(rec)) {
throw new Error('bunyan-loggly requires a raw stream. Please define the type as raw when setting up the bunyan stream.');
}
// loggly prefers timestamp over time
if (data.time) {
data = JSON.parse(JSON.stringify(data));
data.timestamp = data.time;
delete data.time;
}
if (typeof rec === 'object') {
this._buffer.push(data);
// loggly prefers timestamp over time
if (rec.time !== undefined) {
rec.timestamp = rec.time;
delete rec.time;
}
this._checkBuffer();
};
}
Bunyan2Loggly.prototype._processBuffer = function(){
clearTimeout(this._timeoutId);
// write to our array buffer
this._buffer.push(rec);
var content = this._buffer.slice();
this._buffer = [];
// check the buffer, we may or may not need to send to loggly
this.checkBuffer();
for (var i = 0; i < content.length; i++) {
this.logglyClient.log(content[i]);
}
};
Bunyan2Loggly.prototype.checkBuffer = function () {
Bunyan2Loggly.prototype._checkBuffer = function(){
var bunyan2Loggly = this;
if (this._buffer.length < this.buffer) {
return;
}
if (!this._buffer.length) {
return;
}
// duplicate the array, because it could be modified before our HTTP call succeeds
var content = this._buffer.slice();
this._buffer = [];
if(this._buffer.length >= this.bufferLength){
return this._processBuffer();
}
// log multiple (or single) requests with loggly
this.client.log(content);
if(this.bufferTimeout){
clearTimeout(this._timeoutId);
this._timeoutId = setTimeout(
function(){
bunyan2Loggly._processBuffer();
},
this.bufferTimeout
);
}
};
module.exports.Bunyan2Loggly = Bunyan2Loggly;
module.exports = Bunyan2Loggly;
{
"name": "bunyan-loggly",
"version": "0.0.5",
"version": "1.0.0",
"description": "A bunyan stream to transport logs to loggly",
"main": "index.js",
"repository": {
"type": "git",
"url": "https://github.com/smebberson/bunyan-loggly.git"
},
"keywords": [

@@ -15,16 +11,26 @@ "bunyan",

],
"author": "Scott Mebberson",
"license": "ISC",
"bugs": {
"url": "https://github.com/smebberson/bunyan-loggly/issues"
},
"homepage": "https://github.com/smebberson/bunyan-loggly",
"author": "Maurice Butler <maurice.butler@gmail.com>",
"license": "MIT",
"dependencies": {
"loggly": "~1.0.3"
"clone": "^1.0.2",
"loggly": "^1.1.0"
},
"devDependencies": {
"mocha": "~1.18.0",
"should": "~3.1.3",
"bunyan": "~0.22.1"
}
"proxyquire": "^1.7.4",
"tape": "^4.4.0"
},
"directories": {
"test": "test"
},
"scripts": {
"test": "node ./tests"
},
"repository": {
"type": "git",
"url": "git+https://github.com/MauriceButler/bunyan-loggly.git"
},
"bugs": {
"url": "https://github.com/MauriceButler/bunyan-loggly/issues"
},
"homepage": "https://github.com/MauriceButler/bunyan-loggly#readme"
}

@@ -1,3 +0,2 @@

bunyan-loggly
=============
# bunyan-loggly

@@ -15,10 +14,5 @@ A bunyan stream to send logs through to loggly.

token: "your-really-long-input-token",
subdomain: "your-subdomain",
auth: {
username: "your-username",
password: "your-password"
}
subdomain: "your-subdomain"
}
```
> Please note: auth values are NOT required to simply send logs through to loggly.

@@ -31,7 +25,11 @@ ## Usage

var bunyan = require('bunyan'),
Bunyan2Loggly = require('bunyan-loggly').Bunyan2Loggly,
logger;
Bunyan2Loggly = require('bunyan-loggly'),
logglyConfig = {
token: 'your-account-token',
subdomain: 'your-sub-domain'
},
logglyStream = new Bunyan2Loggly(logglyConfig);
// create the logger
logger = bunyan.createLogger({
var logger = bunyan.createLogger({
name: 'logglylog',

@@ -41,6 +39,3 @@ streams: [

type: 'raw',
stream: new Bunyan2Loggly({
token: 'your-account-token',
subdomain: 'your-sub-domain'
})
stream: logglyStream
}

@@ -53,26 +48,25 @@ ]

> Please note: you MUST define `type: 'raw'` as bunyan-loggly expects to recieve objects so that certain values can be changed as required by loggly (i.e. time to timestamp).
> Please note: you MUST define `type: 'raw'` as bunyan-loggly expects to receive objects so that certain values can be changed as required by loggly (i.e. time to timestamp).
### Express logging
## Buffering
This is an example of using bunyan-loggly to store express.js request logs.
bunyan-loggly supports basic buffering and when setup, will only send your logs through to loggly on every x logs. To setup buffering, just pass an integer as the second parameter when creating a new instance of Bunyan2Loggly:
```javascript
var path = require('path'),
bunyan = require('bunyan'),
serializerRequest = require('../lib/serializer-request'),
Bunyan2Loggly = require('bunyan-loggly').Bunyan2Loggly,
request;
var bunyan = require('bunyan'),
Bunyan2Loggly = require('bunyan-loggly'),
logglyConfig = {
token: 'your-account-token',
subdomain: 'your-sub-domain'
},
bufferLength = 5,
logglyStream = new Bunyan2Loggly(logglyConfig, bufferLength);
// create the logger
request = bunyan.createLogger({
name: 'request',
serializers: { req: bunyan.stdSerializers.req },
var logger = bunyan.createLogger({
name: 'logglylog',
streams: [
{
type: 'raw',
stream: new Bunyan2Loggly({
token: 'your-account-token',
subdomain: 'your-sub-domain'
})
stream: logglyStream
}

@@ -82,32 +76,27 @@ ]

// export the middleware
module.exports = function () {
return function (req, res, next) {
// move on straight away
next();
// log this request
request.info({
req : req,
production: process.env.NODE_ENV === 'production'
});
}
}
logger.info({}); // won't send to loggly
logger.info({}); // won't send to loggly
logger.info({}); // won't send to loggly
logger.info({}); // won't send to loggly
logger.info({}); // will send to loggly
logger.info({}); // won't send to loggly
```
## Buffering
### Buffer Timeout
bunyan-loggly supports basic buffering and when setup, will only send your logs through to loggly on every x logs. To setup buffering, just pass an integer as the second parameter when creating a new instance of Bunyan2Loggly:
When buffering, a timeout can be provided to force flushing the buffer after a period of time. To setup a flush timeout, pass a timeout value (in ms) as the third parameter when creating a new instance of Bunyan2Loggly:
```javascript
var bunyan = require('bunyan'),
Bunyan2Loggly = require('bunyan-loggly').Bunyan2Loggly,
logger;
Bunyan2Loggly = require('bunyan-loggly'),
logglyConfig = {
token: 'your-account-token',
subdomain: 'your-sub-domain'
},
bufferLength = 5,
bufferTimeout = 500,
logglyStream = new Bunyan2Loggly(logglyConfig, bufferLength, bufferTimeout);
// create the logger
logger = bunyan.createLogger({
var logger = bunyan.createLogger({
name: 'logglylog',

@@ -117,6 +106,3 @@ streams: [

type: 'raw',
stream: new Bunyan2Loggly({
token: 'your-account-token',
subdomain: 'your-sub-domain'
}, 5)
stream: logglyStream
}

@@ -126,20 +112,3 @@ ]

logger.info({}); // won't send to loggly
logger.info({}); // won't send to loggly
logger.info({}); // won't send to loggly
logger.info({}); // won't send to loggly
logger.info({}); // will send to loggly
logger.info({}); // won't send to loggly
logger.info({}); // will be sent to loggly in 500ms if buffer threshold is not reached
```
Changes
-------
Most recent change, v0.0.4.
- bunyan-loggly now requires to be setup as a [raw stream][rawstream]
[You can read about all changes.][bunyanlogglyhistory]
[rawstream]: https://github.com/trentm/node-bunyan#stream-type-raw "Bunyan raw stream"
[bunyanlogglyhistory]: https://github.com/smebberson/bunyan-loggly/blob/master/History.md "bunyan-loggly history"

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