enchanted-debug

1.0.0 • Public • Published

enchanted-debug

Coverage Status Dependency Status Codeship Status for SindreSvendby/enchanted-debug

a wrapper around the amazing debug package that automaticly adds namespace based on the path and project root.

This module will be obsolete when debug is in version 3, sjekk out this github issue for progress on that

Cons

Performance is not the best, since we use callsite. So keep that in mind.

Pros

  1. Do not need to

Prerequisite

enchanted-debug is a peerDependecy of debug and you can need to specified this your self

So install debug

yarn add debug / npm install --save-exact debug

Installation

yarn add enchanted-debug or npm install --save-exact enchanted-debug

Usage

// assume this  file is under <project-root>/src/services/fetch/index.js
import eDebug from 'enchanted-debug'
// project root folder name, for this project
const { log, error } from eDebug('<project-root>') 
 
log('starting')
error('failed')
log('finished')
 

Output from debug module will be

// output will be:
<project-root>:src:services:fetch starting
<project-root>:error:src:services:fetch: failed
<project-root>:src:services:fetch finished

This would be the same as doing this with plain debug:

import debug from 'debug';
 
const path =  '<project-root>:<subfolder>:<subfolder>:<subfolder>:<filename-without-ending>'
const subpath ='<subfolder>:<subfolder>:<subfolder>:<filename-without-ending>'
const log = debug(`${path}`);
const error = debug(`<project-root>:error:<project-path>`);
 
// use error or log, to log with the module
log('starting')
error('failed')
log('finished')

Good to know

Skip filename ending:

enchanted-debug/src/services/fetch/utils.js =>  enchanted-debug:src:services:fetch:utils

Skip index as last part

enchanted-debug/src/services/fetch/index.js =>  enchanted-debug:src:services:fetch

Failure

if (typeof callstack.length === 'number' && callstack.length > 1) if the above line for some reasons fails, the logging will be done under

Dependencies

only have callsite as a dependency

Credits

Created by the developers in Aller Media

Package Sidebar

Install

npm i enchanted-debug

Weekly Downloads

1

Version

1.0.0

License

ISC

Last publish

Collaborators

  • sindresvendby