Socket
Socket
Sign inDemoInstall

debuggy

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

debuggy

Debugging utility tool for development


Version published
Weekly downloads
2
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 09 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc