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

snooplogg

v5.1.0

Published

Your mind on your logs and your logs on your mind

Downloads

3,398

Readme

SnoopLogg

NPM Version NPM Downloads

Laid back debug logging.

Installation

npm install snooplogg

snooplogg

Features

  • Built-in and custom log types
  • Ability to snoop on other snooplogg instances nested in dependencies
  • Pipe messages to one or more streams
  • Namespacing
  • Filter messages using the DEBUG (or SNOOPLOGG) environment variable
  • Automatic color selection with brightness range
  • Exports chalk library for your convenience.
  • Similar API to TJ's debug:

Examples

debug style:

// app.js

import snooplogg from 'snooplogg';
import http from 'http';

// const debug = require('debug')('http');
const debug = snooplogg('http').log;
const name = 'My App';

debug('booting %o', name);

http.createServer((req, res) => {
	debug(`${req.method} ${req.url}`);
	res.end('hello\n');
}).listen(3000, () => debug('listening'));
// worker.js

import snooplogg from 'snooplogg';

const a = snooplogg('worker:a');
const b = snooplogg('worker:b');
/*
Or you could do this:

const worker = snooplogg('worker');
const a = worker('a');
const b = worker('b');
*/

function work_a() {
  a('doing lots of uninteresting work');
  setTimeout(work_a, Math.random() * 1000);
}

work_a();

function work_b() {
	b('doing some work');
	setTimeout(work_b, Math.random() * 2000);
}

work_b();

Standard console usage:

import log from 'snooplogg';

log.trace('bow'); // writes to stdout/stderr if DEBUG matches + all pipes

log.info('wow')
   .warn('wow')
   .error('wow');

Namespace support:

import snooplogg from 'snooplogg';

const log = snooplogg('myapp');
log.info('bow', 'wow', 'wow'); // writes to stdout/stderr if DEBUG=myapp + all pipes

Stream output to stdout:

import snooplogg from 'snooplogg';

const log = snooplogg.stdio('yippy yo');
log.info('bow', 'wow', 'wow'); // writes to stdout/stderr + all pipes

const log = snooplogg.enable('*')('yippy yay');
log.info('bow', 'wow', 'wow'); // writes to stdout/stderr + all pipes

Pipe output to a stream (such as a file or socket):

import snooplogg from 'snooplogg';

const log = snooplogg
	.pipe(someWritableStream);

log.info('yippy', 'yo');

Listen for messages from all SnoopLogg instances, even from other dependencies:

import snooplogg, { snoop } from 'snooplogg';

snoop();

const log = snooplogg('bumpin');

log('one');
log
  .trace('two')
  .debug('three')
  .info('and to the four');

log.warn(`It's like this`);
log.error('and like that');
log.fatal('and like this');

Custom log types:

import snooplogg, { type } from 'snooplogg';

type('jin', { color: 'cyan' });
type('juice', { color: 'yellow' });

const log = snooplogg();

log.jin('parents ain\'t home');
log.juice('too much drama', true);

Console:

import snooplogg from 'snooplogg';

snooplogg.enable('*').console.log('dawg gone');

API

snooplogg()

Creates a namespaced logger as well as defines the global namespaced logger.

snooplogg.log(msg)

Outputs a message using the standard console.log() format syntax.

snooplogg.config(options)

Allows you to set various instance specific options.

  • colors - (Array) An array of color names to choose from when auto-selecting a color, specifically for rendering the namespace.
  • minBrightness - (Number) The minimum brightness to auto-select a color. Value must be between 0 and 255 as well as less than or equal to the maxBrightness. Defaults to 80.
  • maxBrightness - (Number) The maximum brightness to auto-select a color. Value must be between 0 and 255 as well as greater than or equal to the minBrightness. Defaults to 210.
  • theme - (String) The name of the default theme to use. Defaults to standard.
  • maxBufferSize - (Number) The maximum number of log lines to buffer. Used to flush prior messages to new pipes.

Returns the original SnoopLogg instance.

Enabling Logging

By default, Snooplogg only prints messages if the the DEBUG or SNOOPLOGG environment variables are set.

# macOS and Linux
$ DEBUG=izzle node loggfather.js

# Windows PowerShell
> $Env:DEBUG="izzle" node loggfather.js

# Windows Command Prompt
> set DEBUG=izzle
> node loggfather.js

Note: You may also use the SNOOPLOGG environment variable to avoid conflicts with other libraries that use debug

You can also use any environment variable you want by simply calling enable() before logging.

import snooplogg from 'snooplogg';

// change the global environment variable name
snooplogg.enable(process.env.LOGGFATHER);

Note: The console log types (info, warn, error, etc) are for display only. snooplogg does not support log level filtering, only namespace filtering via the SNOOPLOGG (or DEBUG) environment variable or by enable().

Global Defaults

SnoopLogg allows you to set defaults using environment variables that apply to all SnoopLogg instances.

  • SNOOPLOGG_COLOR_LIST - A comma-separated list of supported color names.
  • SNOOPLOGG_DEFAULT_THEME - Sets the theme.
  • SNOOPLOGG_MAX_BUFFER_SIZE - Sets the maxBufferSize.
  • SNOOPLOGG_MAX_BRIGHTNESS - Sets the maxBrightness.
  • SNOOPLOGG_MIN_BRIGHTNESS - Sets the minBrightness.

License

MIT