Socket
Book a DemoInstallSign in
Socket

debug-fn

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

debug-fn

Wraps visionmedia/debug to execute a function on demand

1.0.3
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

debug-fn

NPM version Build Status

Wraps visionmedia/debug to execute a function on demand based on the DEBUG env variable

Install

npm install --save-dev debug-fn

Usage

A logger is created in the same way as debug, the difference is that the logger receives a function instead of multiple arguments, the function will be called based on debug rules (which checks the value of the DEBUG env variable)

// file example.js
import debugFn from 'debug-fn'

const logger = debugFn('app')

logger(function (log) {
  log('hello')
})

Running example.js with the DEBUG env set to app

$ DEBUG=app node example.js
  app hello! +0ms

Running example.js without the DEBUG env doesn't log anything

$ node example.js

NOTE: you could also use this.log inside logger's function argument (which is the same as the log argument)

// file example.js
import debugFn from 'debug-fn'

const logger = debugFn('app')

logger(function () {
  this.log('hello')
})

If you want to overwrite debug's custom logger, the logger instance is stored in logger.logger e.g.

// logger.logger is the result of calling `debug('app')`
logger.logger.log = function () {
  // custom logic to handle the output
}

Why?

Imagine you have a cpu expensive operation that you only want to be executed when DEBUG is set, debug can't do that out of the box, this wrapper allows you to do that by wrapping your cpu expensive operation in a function

License

MIT © Mauricio Poppe

Keywords

debug

FAQs

Package last updated on 14 Dec 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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.