home nodejitsu.com


Vote on HN

About the author

Name
Charlie Robbins
indexzero
indexzero
Location
New York, NY

About this article

Date Released:
Thursday, Jan 13 2011
Code Examples:
  • usage.js

Also by this author

  • update on price changes
  • waiting for godot
  • new nodejitsu handbook
  • ten lessons learned maintaining nodejs modules
  • on disrupting pricing models
  • writing cli apps with flatiron
  • scaling isomorphic javascript code
  • the nodejs philosophy
  • package dependencies done right
  • updating node http proxy
  • rest easy test any api in nodejs
  • put your logs anywhere with winston
  • merry christmas heres some code
  • using sys inherits in node js
  • nodejs cloud server in three minutes

About nodejitsu

nodejitsu is a node.js application hosting company from new york city.

we are community leaders in the node.js project.

we build awesome open-source projects that you love and use.

Follow @nodejitsu

Logging, Logs, and Loggly in Node.js

This is Part One of a two part post on logging in node.js — I think every developer has a love/hate relationship with their log files. They love them when they have to debug, optimize or fix a problem, but they hate setting them up and later distributing, aggregating and searching log files. There are a lot of utilities out there for managing your logs, but one caught our eye at Nodejitsu: Loggly. That's why we're happy to announce the release of node-loggly: A library for interacting with the Loggly API.

Using node-loggly

There is a robust amount of documentation for node-loggly on the GitHub project page. To get started you want to install node-loggly using npm:

  npm install loggly

Here is a quick summary of basic logging with node-loggly. We'll require loggly, configure it with an account, and log some test data:

var loggly = require('loggly');
var config = {
  subdomain: "your-subdomain",
  auth: {
    username: "your-username",
    password: "your-password"
  }
};

var client = loggly.createClient(config);

//
// Logging with no callback ('fire and forget')
//
client.log('your-really-long-input-token', '127.0.0.1 - Theres no place like home');

//
// Logging with a callback
//
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
});

Logging and Nodejitsu

Last month Heroku announced "Sweet Logging" which perplexed me as to how their customers functioned before this feature. I wonder how they were able to manage their own log files without such a feature. Regardless, you can be sure that given our Loggly-backed infrastructure Nodejitsu users will be able to see logs for all applications and servers with ease from the start.

What's next?

So why is this a two part post? Well we've been working on more than just the Loggly API. After taking a survey of the logging libraries available for node.js it was clear there was a missing link. Our interpretation of this missing link is a new multi-transport logging library: winston. A transport is essentially a storage device for your logs. Each instance of the winston logger can have multiple transports configured at different levels.We will be releasing winston in the next few days, so check back soon.