Giter Club home page Giter Club logo

node-loggly-bulk's Introduction

node-loggly-bulk

Version npmnpm Downloads

NPM

A client implementation for Loggly in node.js. Check out Loggly's Node logging documentation for more.

Usage

The node-loggly-bulk library is compliant with the Loggly API. Using node-loggly-bulk you can send logs to Loggly.

Getting Started

Before we can do anything with Loggly, we have to create a client with valid credentials. We will authenticate for you automatically:

  var loggly = require('node-loggly-bulk');

  var client = loggly.createClient({
    token: "your-really-long-input-token",
    subdomain: "your-subdomain",
    //
    // Optional: Tag to send with EVERY log message
    //
    tags: ['global-tag']
  });

Logging

There are two ways to send log information to Loggly via node-loggly-bulk. The first is to simply call client.log with an appropriate input token:

  client.log('127.0.0.1 - Theres no place like home', function (err, result) {
    // Do something once you've logged
  });

Note that the callback in the above example is optional, if you prefer the 'fire and forget' method of logging:

  client.log('127.0.0.1 - Theres no place like home');

Logging with Tags

If you're using Loggly's tags functionality, simply include an array of tags as the second argument to the log method:

  client.log('127.0.0.1 - Theres no place like home', [ 'dorothy' ], function (err, result) {
    // Do something once you've logged
  });

note Tags passed into the log function will be merged with any global tags you may have defined.

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

  var source = {
    foo: 1,
    bar: 2,
    buzz: 3
  };

  input.log(source);

will be logged as:

  foo=1,bar=2,buzz=3

Logging JSON Objects

It is also possible to log complex objects using the new JSON capabilities of Loggly. To enable JSON functionality in the client simply add 'json: true' to the configuration:

  var config = {
    token: 'token',
    subdomain: "your-subdomain",
    json: true
  };

When the json flag is enabled, objects will be converted to JSON using JSON.stringify before being transmitted to Loggly. So

  var source = {
    foo: 1,
    bar: 2,
    buzz: {
      sheep: 'jumped',
      times: 10
    }
  };

  input.log(source);

will be logged as:

  { "foo": 1, "bar": 2, "buzz": {"sheep": "jumped", "times": 10 }}

Logging arrays

It is possible to send arrays, which will result in one single request to Loggly.

  input.log([ {iam:'number 1'}, {iam:'number 2'} ])

Installation

Installing npm (node package manager)

  $ curl http://npmjs.org/install.sh | sh

Installing node-loggly-bulk

  $ npm install node-loggly-bulk

Run Tests

  $ npm run test

node-loggly-bulk's People

Contributors

bacchusrx avatar bradfol avatar brandongoode avatar buildmaster avatar capelio avatar coderarity avatar ehedenst avatar freeall avatar indexzero avatar jcrugzz avatar jonastryggvi avatar justinmares avatar kevinegami avatar kordless avatar mafintosh avatar marak avatar martinagold avatar mauricebutler avatar mend-for-github-com[bot] avatar michal-bures avatar mmalecki avatar mostlyjason avatar nagoodman avatar shwetajain148 avatar thefirstspine avatar varshneyjayant avatar viggeh avatar whtswrng avatar zdenek-machek-swi avatar

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.