Coder Social home page Coder Social logo

debug's Introduction

@deps/debug Build Status

Simple debug logger for Browser and Node.js.

Features

  • Provide a single debug function
  • Add caller's file name as prefix to log using StackTracey
  • Support TypeScript
  • Support ES modules import
  • Support Browser and Node.js

This library is inspired by visionmedia/debug.

Install

Install with npm:

npm install @deps/debug

Usage

API

This library provide a debug function.

This debug function output to console if DEBUG MODE is enabled.

import { debug } from "@deps/debug";

debug("log text"):
// => Output to console: "log text"

Tips ๐Ÿ’ก

@deps/debug also provide debug function as debugLog. debugLog is a just alias to debug function.

You can use debugLog to avoid conflict naming with Node.js's utils, visionmedia/debug, or other modules.

import { debugLog } from "@deps/debug";

debugLog("log text"):
// => Output to console: "log text"

Enable DEBUG MODE

debug accept following values as DEBUG.

  • *: Enable all debug log
  • prefix:* Enable debug log that start with prefix:
  • -prefix:* Disable debug log that start with prefix:

Also, debug accept Multiple values as DEBUG. The values should be separated by ,.

a,b,c

Node.js

Enable DEBUG MODE by Environment Variables.

DEBUG=*
DEBUG=prefix:*
DEBUG=-prefix:*
DEBUG=-p1,p2,p3

Notes: Node.js add file name as prefix automatically.

When you specify DEBUG=*/your-file.js, this library output log that file name is your-file.js.

// src/your-file.js
import { debug } from "@deps/debug";

debug("log text"):
// => "src/your-file.js: log text"
debug("log text");
// => No output

Browser

Enable DEBUG MODE by localStorage API.

localStorage.debug = '*';
localStorage.debug = 'prefix:*'
localStorage.debug = '-prefix:*'
localStorage.debug = 'p1,p2,p3'

Force disable logging

DEBUG_CONTROLLER is shared value of the debug module.

import { DEBUG_CONTROLLER } from "@deps/debug"
// Stop logging
DEBUG_CONTROLLER.disable();
// Start logging(by default)
DEBUG_CONTROLLER.enable();

Also you can force enable. This ignore -prefix pattern.

import { DEBUG_CONTROLLER } from "@deps/debug"
DEBUG_CONTROLLER.forceEnable();

Changelog

See Releases page.

Running tests

Install devDependencies and Run npm test:

npm i -d && npm test

Contributing

Pull requests and stars are always welcome.

For bugs and feature requests, please create an issue.

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

License

MIT ยฉ azu

Some codes are copied from following:

debug's People

Contributors

azu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

debug's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.