question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not printing any debug statements

See original GitHub issue

I’m sure i’m doing something wrong, but I have this code and it’s not printing any debug statement’s

#!/usr/bin/env node

const axios = require('axios')
const program = require('commander')
const debug = require('debug')
const config = require('./config.json')
const getJwt = require('./getJwt.js')
const package = require('./package.json')
const { envs } = require('./util')

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) {
  console.log('in program.debug')
  debug.enable('debug')
}
console.log('debug is enabled =', debug.enabled('debug'))
debug('here') // WHY ISN'T THIS PRINTING?

And here’s the output from my command:

$ ./deleteUserData -e dev -m foo@example.com -p myPassword -a -b
in program.debug
debug is enabled = true

I’m using version 4.1.1 of debug

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
TooTallNatecommented, Mar 19, 2019

To create a debug instance that is always enabled, do this:

const debug = require('debug')('my-namespace');

debug.enabled = true;

debug('some stuff');
3reactions
Qix-commented, Mar 19, 2019

No.

A namespace is just a way to group logical sets of logs together. debug gives you the ability to filter out particular namespaces.

How you should be using debug is via the environment variable, not via a flag. This is what it’s for - it’s not necessarily meant to be a logging mechanism.

/* 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Debug log is not printing - Salesforce Developer Community
Debug log is not printing. I have created a Batch class to delete records and it is working fine but when i am...
Read more >
Xcode 12: print() not printing to debug area - Apple Developer
My debug console was not printing any information after the 12.0 update. The "View --> Debug Area --> Activate Console" worked for me...
Read more >
How to Improve Print Statement Debugging - TotalView
PrintF debugging can get out of hand, fast! See how to improve Print Statement debugging with this in-depth article.
Read more >
printf statement not printing on console during debugging
I re-compiled the code and ran again and same problem - still the printf string did not got printed - I am sure...
Read more >
Some Debug.Log executes not printing - Unity Answers
I use Debug.Log for debug trace statements. Some of my Debug.Log print statements are not printing. I have tried putting: Debug.logger.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found