@microphi/debug
TypeScript icon, indicating that this package has built-in type declarations

2.7.2 • Public • Published

@microphi/debug

Super simple wrapper around console.log

Install

@microphi/debug

Use in nodejs

import { getDebugger } from "@microphi/debug";

export const d = getDebugger('namespace1');

// any where in the code
d('test');
setTimeout(() => {
  d('hello there');
}, 500);

Set DEBUG environment variable with a comma separated list of regex: if a match happens with a namespace then the text will be logged using console.log.

nodejs example output

Use in the browser

Set localStorage.debug with a comma separated list of regex: if a match happens with a namespace then the text will be logged using console.log.

browser example output

In this case localStorage.debug is set to musicbox:*

OnMessage handler

With OnMessage is possible to handle each message logged regardless of the regexes provided. This may be usefull to send the logs to a server or to to store them to a file.

onMessage((message) => {
  // do something
});

Readme

Keywords

Package Sidebar

Install

npm i @microphi/debug

Weekly Downloads

24

Version

2.7.2

License

none

Unpacked Size

63.8 kB

Total Files

29

Last publish

Collaborators

  • davidecavaliere