/js-debugger

Debug your JS

Primary LanguageJavaScriptMIT LicenseMIT

JSdebugger

A suite of tools to debug your JavaScript in the browser and in Node.

NPM Build Status

Overview

JSdebugger uses morgan to log HTTP requests, log4js-node for node and js-logger for the browser.

Wraps js-logger and log4js-node with a unique API and some default values.

Install

npm install js-debugger

How it works

browser

Options
Name Type Default Description
disabled Boolean false If set to true disable all logs.
globalDebug string false A name for the global debug variable.
globalConsole string false A name for the global console variable.
level string 'error' Default maximun level.

Exemple

import jsdebugger from 'js-debugger';

// passing options
const debug = jsdebugger(options);
const _log = debug('module').level('debug');

// or using the default options
const _log = jsdebugger('module').level('debug');

_log.info('info');
_log.debug('debug');
_log.verbose('verbose');
_log.warn('warn');
_log.error('error');
_log.fatal('fatal');
_log.trace('trace');

alt text

Node

You can use all the options from the browser plus this ones:

Options
Name Type Default Description
line Boolean Object false Display line numbe, see line.
morgan Object undefined Options for morgan, see morgan.
notify Object undefined Options for notify, see notify.
line

Enable line number, thanks to log4js-node-extend.

line: true;

// or

line: {
  path: __dirname,
  format: 'at @name (@file:@line:@column)'
};
morgan

Enable morgan with express, please check the API.

morgan: {
  app: app, // The express app object.
  format: 'dev', // morgan format.
  opts: {}, // morgan options.
};

alt text

notify

Enable notifications by email, please check the API.

morgan: {
  smtp: Object, // The SMTP object.
  email: {
    from: string,
    to: string,
    subject: string
  }
};

Exemple

const jsdebugger = require('js-debugger');

// passing options
const debug = jsdebugger(options);
const _log = debug('module').level('debug');

// or using the default options
const _log = jsdebugger('module').level('debug');

_log.info('info');
_log.debug('debug');
_log.verbose('verbose');
_log.warn('warn');
_log.error('error');
_log.fatal('fatal');
_log.trace('trace');

alt text

Contributing

Test

The unit test are written in Mocha. Please add a unit test for every new feature or bug fix. npm test will run the tests.

Documentation

Please read and add documentation for every API change.

Feel free to contribute!

License

Copyright (c) 2017 Bruno Santos Licensed under the MIT license.