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

captains-log

v2.0.5

Published

Lightweight logger with a simple pass-through configuration for use with fancier logging libraries

Downloads

353,840

Readme

captains-log

NPM version   Build Status   Build status on Windows

Lightweight logger with a simple pass-through configuration for use with fancier logging libraries. Used by the Sails framework. Optional support for colorized output, custom prefixes, and log levels (using npm's logging conventions.)

Installation

$ npm install captains-log

Usage

var log = require('captains-log')();

log('hi');
Logging at a particular level

By default, if you just call log(), captains-log will write your log output at the "debug" log level. You can achieve the same effect by writing log.debug().

IMPORTANT NOTE: npm calls this level log.http(), but we call it debug. If you use log(), the logger sees this as a call to log.debug())

Here are all of the log-level-specific methods which are available in captains-log out of the box:

log.silly();

log.verbose();

log.info();

log.debug()

log.warn();

log.error();

Configuring a custom logger

To use a different library, overrides.custom must already be instantiated and ready to go with (at minimum) an n-ary .debug() method.

Implementing the simplest possible override
var log = require('captains-log')({ custom: customLogger });

log('hello', 'world');
// yields => "Hello world"

This assumes customLogger works as follows:

customLogger.debug()
customLogger.debug('blah')
customLogger.debug('blah', 'foo')
customLogger.debug('blah', 'foo', {bar: 'baz'})
customLogger.debug('blah', 'foo', {bar: 'baz'}, ['a', 3], 2, false);
// etc.

For example:

var customLogger = console.log.bind(console);
Configure inspect

When an object is passed, and inspect is set to true (it is true, by default), you can configure the inner inspect function options, by passing an inspectOptions parameter:

var log = require('captains-log')({inspectOptions: {colors: true, depth: null}});

log('hello', 'world', {this:'is', a: 'nice', object: new Date()});

The previous code renders the object with colors.

result

Using Winston

Formerly, this module encapsulated winston, a popular logger by @indexzero and the gals/guys over at Nodejitsu. But eventually, we made Winston optional to make captains-log as lightweight as possible and reduce the number of npm installs and require()s necessary for its usage in other modules.

But Winston is awesome! And it's a great fit for many apps, giving you granular control over how log output is handled, including sending emails, logging to multiple transports, and other production-time concerns.

To boot up a captains-log that writes to Winston, do the following:

var log = require('captains-log')({
  custom: new (require('winston').Logger)({
    levels     : ...,
    transports : ...
  })
});

Why use a custom logger?

It it can useful to configure a custom logger-- particularly for regulatory compliance and organizational requirements (i.e. if your company is using a particular logger in other apps.) In the context of Sails, configuring a custom logger also allows you to intercept all log messages automatically created by the framework, which is a quick way to set up email notifications about errors and warnings.

That said, don't feel like you have to use a custom logger if you want these sorts of notifications. In fact, there are usually more straightforward ways to implement features like Slack, SMS, or email notifications. For example, in Sails, consider customizing your responses/serverError.js file. Or check out a product like Papertrail.

Help

If you have further questions or are having trouble, click here.

Bugs   NPM version

To report a bug, click here.

Contributing   Build Status

Please observe the guidelines and conventions laid out in the Sails project contribution guide when opening issues or submitting pull requests.

NPM

License

This package, like the Sails framework, is free and open-source under the MIT License.