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 🙏

© 2024 – Pkg Stats / Ryan Hefner

log-driver

v1.2.7

Published

log-driver is a simple logging framework for logging to stdout

Downloads

7,218,501

Readme

Log Driver

Build Status NPM Version codecov.io

Logdriver is a node.js logger that only logs to stdout.

You're going to want to log the output of stdout and stderr anyway, so you might as well put all your logging through stdout. Logging libraries that don't write to stdout or stderr are missing absolutely critical output like the stack trace if/when your app dies.

There are some other nice advantages:

  • When working on your app locally, logs just show up in stdout just like if you'd used console.log(). That's a heck of a lot simpler than tailing a log file.
  • Logging transports can be externalized from your app entirely, and completely decoupled. This means if you want to log to irc, you write an irc client script that reads from stdin, and you just pipe your app's output to that script.
node yourapp.js 2>&1 | node ircloggerbot.js 
  • You can still easily log to a file on a production server by piping your stdout and stderr to a file like so when you initialize your app:
node yourapp.js 2>&1 >> somefile.log 

NB: If you're logging to a file, Logrotate is probably going to be your best friend.

  • You can still easily log to syslog by piping your stdout and stderr to the 'logger' command like so:
node yourapp.js 2>&1 | logger

Usage:

Getting the default logger:

var logger = require('log-driver').logger;

This logger has levels 'error', 'warn', 'info', 'debug', and 'trace'. If you don't like those levels, change the default:

var logger = require('log-driver')({
  levels: ['superimportant', 'checkthisout', 'whocares' ]
});
logger.whocares("brangelina in lover's quarrel!");

Specifying what log level to log at to make logs less chatty:

var logger = require('log-driver')({ level: "info" });
logger.info("info test"); 
logger.warn("warn test"); 
logger.error("error test"); 
logger.trace("trace test"); 

output:

[info] "2013-03-26T18:30:14.570Z"  'info test'
[warn] "2013-03-26T18:30:14.573Z"  'warn test'
[error] "2013-03-26T18:30:14.574Z"  'error test'

(notice the trace() call was omitted because it's less than the info level.

Turning off all log output (sometimes nice for automated tests to keep output clean):

var logger = require('log-driver')({ level: false });

Using the same logger everywhere: The last logger you created is always available this way:

var logger = require('log-driver').logger;

This way, if you use only one logger in your application (like most applications), you can just configure it once, and get it this way everywhere else.

Don't like the logging format? Just change it by passing a new formatting function like so:

var logger = require('log-driver')({ 
  format: function() {
    // let's do pure JSON:
    return JSON.stringify(arguments);
  }
});