Coder Social home page Coder Social logo

bunyan-loggly's Introduction

bunyan-loggly

A bunyan stream to send logs through to loggly.

Configuration

bunyan-loggly uses node-loggly under the hood. As such, when configuring bunyan-loggly as a stream for bunyan, you need to pass in the standard and required node-loggly configuration object.

For example:

{
	token: "your-really-long-input-token",
	subdomain: "your-subdomain",
	auth: {
    	username: "your-username",
    	password: "your-password"
	}
}

Please note: auth values are NOT required to simply send logs through to loggly.

Usage

This is a basic usage example.

var bunyan = require('bunyan'),
	Bunyan2Loggly = require('bunyan-loggly').Bunyan2Loggly,
	logger;

// create the logger
logger = bunyan.createLogger({
	name: 'logglylog',
	streams: [
		{
			type: 'raw',
			stream: new Bunyan2Loggly({
				token: 'your-account-token',
				subdomain: 'your-sub-domain'
			})
		}
	]
});

logger.info({});

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).

Express logging

This is an example of using bunyan-loggly to store express.js request logs.

var path = require('path'),
	bunyan = require('bunyan'),
	serializerRequest = require('../lib/serializer-request'),
	Bunyan2Loggly = require('bunyan-loggly').Bunyan2Loggly,
	request;

// create the logger
request = bunyan.createLogger({
	name: 'request',
	serializers: { req: bunyan.stdSerializers.req },
	streams: [
		{
			type: 'raw',
			stream: new Bunyan2Loggly({
				token: 'your-account-token',
				subdomain: 'your-sub-domain'
			})
		}
	]
});

// 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'
		});

	}

}

Buffering

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:

var bunyan = require('bunyan'),
	Bunyan2Loggly = require('bunyan-loggly').Bunyan2Loggly,
	logger;

// create the logger
logger = bunyan.createLogger({
	name: 'logglylog',
	streams: [
		{
			type: 'raw',
			stream: new Bunyan2Loggly({
				token: 'your-account-token',
				subdomain: 'your-sub-domain'
			}, 5)
		}
	]
});

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

Changes

Most recent change, v0.0.4.

  • bunyan-loggly now requires to be setup as a raw stream

You can read about all changes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.