#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
Performance is not the best, since we use callsite. So keep that in mind.
My intention is for use on server side. how this will work on the browser with minifiers and I haven't thought of
Do not need to specify a namespace for each module. you only specify the project root folder,
This give the following benefits:
- less work
- lower chance of a copy/paste mistake.
- follow debug conventions automatically.
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
yarn add enchanted-debug
or npm install --save-exact enchanted-debug
// 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')
enchanted-debug/src/services/fetch/utils.js => enchanted-debug:src:services:fetch:utils
enchanted-debug/src/services/fetch/index.js => enchanted-debug:src:services:fetch
if (typeof callstack.length === 'number' && callstack.length > 1)
if the above line for some reasons fails, the logging will
be done under
only have callsite as a dependency
Created by the developers in Aller Media