-
Notifications
You must be signed in to change notification settings - Fork 936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not printing any debug statements #696
Comments
Debug is a function that returns a function. The first invocation to debug takes the namespace and returns the actual function to make logging messages Your call to debug just creates namespaces but doesn't use them. You need to store the result somewhere and use it. Most people do this: const debug = require('debug')('some:namespace'); |
I don't want to do that b/c i want to enable it ONLY if a flag is passed in. From what i understand from the docs, doesn't that namespace automatically enable the debug flag? |
No. A namespace is just a way to group logical sets of logs together. How you should be using /* auth.js */
const debug = require('debug')('my-app:auth');
debug('this has something to do with authentication');
/* db.js */
const debug = require('debug')('my-app:db');
debug('this has something to do with the database');
/* index.js */
require('./db');
require('./auth'); $ DEBUG='my-app:*' node ./index.js
my-app:auth this has something to do with authentication +0ms
my-app:db this has something to do with authentication +0ms
$ DEBUG='my-app:auth' node ./index.js
my-app:auth this has something to do with authentication +0ms etc. |
If i have to use an env var i will set it in the script, but this is a script that I ideally users don't have to know to pass in env vars + flags + stand on their head and chug beer through their eyeball sockets. Ideally they just pass in flags. I'll tinker with your example above and see if i can get wrangle up what i'm trying to do. should be doable. |
To create a const debug = require('debug')('my-namespace');
debug.enabled = true;
debug('some stuff'); |
Actually setting the env var in the script doesn't work. Should it? #!/usr/bin/env node
const axios = require('axios')
const program = require('commander')
const debug = require('debug')('delete')
console.log('process.env.DEBUG = ', process.env.DEBUG)
program
.usage('[options]')
.description('Delete files/data for a specific account')
.option('-v --version', package.version)
.option('-e --env <env>', 'Environment to create account for. Options are "dev", "qa", stage", or "prod"')
.option('-m, --email <required>', 'email')
.option('-p, --password <required>', 'password')
.option('-a --all', 'Remove all files and documents')
.option('-b --debug', 'Enable debug mode')
.parse(process.argv)
if (program.debug) {
process.env.DEBUG = 'delete'
console.log('process.env.DEBUG = ', process.env.DEBUG)
}
debug('here') // THIS WONT PRINT WHEN SETTING THE ENV VAR IN THE SCRIPT Without setting the flag when calling the script, it doesn't work and this is my output: $ node ./deleteUserData -e dev -m foo@example.com -p myPassword -a -b
process.env.DEBUG = undefined
in program.debug
process.env.DEBUG = delete When i set the env var when calling the script it does work. Curious if this is expected behavior. $ DEBUG='delete' node ./deleteUserData -e dev -m foo@example.com -p myPassword -a -b
process.env.DEBUG = delete
in program.debug
process.env.DEBUG = delete
delete here +0ms |
You have to set the environment variable before the initial call to |
Just to point out the documentation shows debug.enable as a function. But doesn't seem to exist. Setting .enabled works |
I'm sure i'm doing something wrong, but I have this code and it's not printing any
debug
statement'sAnd here's the output from my command:
I'm using version
4.1.1
ofdebug
The text was updated successfully, but these errors were encountered: