npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

sgoodwin-loggly

v0.3.11

Published

A client implementation for Loggly cloud Logging-as-a-Service API

Readme

node-loggly

A client implementation for Loggly in node.js

Installation

Installing npm (node package manager)

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

Installing node-loggly

  $ [sudo] npm install loggly

Usage

The node-loggly library is compliant with the Loggly API. Using node-loggly is easy for a variety of scenarios: logging, working with devices and inputs, searching, and facet searching.

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('loggly');
  var config = {
    subdomain: "your-subdomain",
    auth: {
      username: "your-username",
      password: "your-password"
    }
  };
  var client = loggly.createClient(config);

Logging

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

  client.log('your-really-long-input-token', '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('your-really-long-input-token', '127.0.0.1 - Theres no place like home');

The second way to send log information to Loggly is to do so once you've retrieved an input directly from Loggly:

  client.getInput('your-input-name', function (err, input) {
    input.log('127.0.0.1 - Theres no place like home');
  });

Again the callback in the above example is optional and you can pass it if you'd like to.

Logging Shallow JSON Object Literals 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 Objects to JSON Enabled Loggly Inputs

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 = {
    subdomain: "your-subdomain",
    auth: {
      username: "your-username",
      password: "your-password"
    },
    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 }}

Searching

Searching with node-loggly is easy. All you have to do is use the search() method defined on each Loggly client:

  var util = require('util');
  
  client.search('404', function (err, results) {
    // Inspect the result set
    util.inspect(results.data);
  });

The search() exposes a chainable interface that allows you to set additional search parameters such as: ip, input name, rows, start, end, etc.

  var util = require('util');
  
  client.search('404')
        .meta({ ip: '127.0.0.1', inputname: test })
        .context({ rows: 10 })
        .run(function (err, results) {
          // Inspect the result set
          util.inspect(results.data);
        });

The context of the search (set using the .context() method) represents additional parameters in the Loggly API besides the search query itself. See the Search API documentation for a list of all options.

Metadata set using the .meta() method is data that is set in the query parameter of your Loggly search, but : delimited. For more information about search queries in Loggly, check out the Search Language Guide on the Loggly Wiki.

Facet Searching

Loggly also exposes searches that can return counts of events over a time range. These are called facets. The valid facets are 'ip', 'date', and 'input'. Performing a facet search is very similar to a normal search:

  var util = require('util');
  
  client.facet('ip', '404')
        .context({ buckets: 10 })
        .run(function (err, results) {
          // Inspect the result set
          util.inspect(results.data);
        });

The chaining and options for the facet method(s) are the same as the search method above.

Working with Devices and Inputs

Loggly exposes several entities that are available through node-loggly: inputs and devices. For more information about these terms, checkout the Loggly Jargon on the wiki. There are several methods available in node-loggly to work with these entities:

  //
  // Returns all inputs associated with your account
  //
  client.getInputs(function (err, inputs) { /* ... */ });
  
  //
  // Returns an input with the specified name
  //
  client.getInput('input-name', function (err, input) { /* ... */ });
  
  //
  // Returns all devices associated with your account
  //
  client.getDevices(function (err, devices) { /* ... */ });

  //
  // Removes device from all inputs
  //
  client.removeDevice('device-ip', function (err, result) { /* ... */ });

Run Tests

All of the node-loggly tests are written in vows, and cover all of the use cases described above. You will need to add your Loggly username, password, subdomain, and a two test inputs to test/data/test-config.json before running tests. When configuring the test inputs on Loggly, the first test input should be named 'test' using the HTTP service. The second input should be name 'test_json' using the HTTP service with the JSON logging option enabled:

  {
    "subdomain": "your-subdomain",
    "auth": {
      "username": "your-username",
      "password": "your-password"
    },
    "inputs": {
      "test": {
        //
        // Token and ID of your plain-text input.
        //
        "token": "your-really-long-token-you-got-when-you-created-an-http-input",
        "id": 000,
        "name": "name-of-your-text-input"
      },
      "test_json": {
        //
        // Token and ID of your JSON input.
        //
        "token": "your-really-long-token-you-got-when-you-created-an-http-input",
        "id": 001,
        "name": "name-of-your-json-input"
      },
    }
  }

Once you have valid Loggly credentials you can run tests with vows:

  $ npm test

Author: Charlie Robbins

Contributors: Marak Squires, hij1nx, Kord Campbell, Erik Hedenström,