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

debuggy

v1.0.0

Published

Debugging utility tool for development

Downloads

16

Readme

debuggy

Debugging utility tool for development

npm travis coveralls

This utility is similar to the debug module but without being a singleton, that is, it doesn't enable the debug mode of other third-party modules, which is undesirable. By default, the DEBUG environment variable is checked and it can contain any value, e.g. DEBUG=true.

The default formatter prints the messages to the stdout but you're free to log them anywhere by configuring a custom formatter. It also allows subnamespaces similar to the bole module.

// app.js
var debuggy = require('debuggy');
var logger = debuggy.createLogger();
var debug = logger('boot')('http').debug;

debug('Booting up HTTPS server');
$ node app.js
$ DEBUG=true node app.js
2015-01-12T14:17:00.302+01:00 +0ms boot:http Booting up HTTPS server

Custom formatter and environment variable

var util = require('util');
var debuggy = require('./lib');

var logger = debuggy.createLogger({
  env: 'TEST',
  // This is the default formatter function, adapt it to your needs
  format: function (data) {
    console.log(this.isoDate(data.date) + ', ' +
        this.delay(data.delay) +
        (data.namespace ? ', ' + data.namespace : '') + ', ' +
        util.format.apply(null, data.arguments));
  }
});
var debug = logger('boot')('http').debug;

// If process.env.TEST is truthy is will print the message
debug('Booting up HTTPS server');
$ node app.js
$ DEBUG=true node app.js
$ TEST=true node app.js
2015-01-12T14:17:50.207+01:00, +0ms, boot:http, Booting up HTTPS server

module.createLogger([options]) : Function
Returns a new logger instance. This instance is a function that creates a namespace when called (the namespace is optional). This new namespace can also create new subnamespaces, and so on. Each "namespace-maker" function has a debug function to log the messages.

var logger = require('debuggy').createLogger();
var debug;

debug = logger.debug;
// debug('foo') <timestamp> <delay> 'foo'

debug = logger('a').debug;
// debug('foo') -> <timestamp> <delay> a 'foo'

debug = logger('a')('b').debug;
// debug('foo') -> <timestamp> <delay> a:b 'foo'

Options:

  • env - String
    Name of the environment variable that's checked to print the messages or not. Default is DEBUG.

  • format - Function
    Function that formats the messages. By default, it prints to the stdout. It receives one argument, data, an object with the raw data. It contains the following properties:

    • arguments - Array
      Array of arguments passed to logger.debug().
    • date - Date
      Date instance of the current timestamp.
    • delay - Number
      Milliseconds between logging calls.
    • namespace - String | undefined
      Name of the namespace.

    this points to an object with some formatting functions:

    • this.isoDate(date) : String
      Returns de ISO date as string including the timezone offset.
    • this.delay(ms) : String
      Returns a more readable string representation of the delay between logging calls.

logger.debug(...arguments) : undefined
Logs a message. The parameters are untouched and are available in the custom formatter function in the data.arguments property.