Skip to content
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

Setting verbose mode doesn't set the logger level do 'debug' #172

Closed
karlitos opened this issue Apr 17, 2020 · 9 comments
Closed

Setting verbose mode doesn't set the logger level do 'debug' #172

karlitos opened this issue Apr 17, 2020 · 9 comments
Assignees

Comments

@karlitos
Copy link

Describe the bug
I searched for a way to detect, whether the -v/--verbose flag was set. My expectation was to look at the level attribute of the logger parameter in the action call.

To Reproduce
Steps to reproduce the behavior:

program.command('test', 'Just a test')
	.action((args, options, logger) => {
                 // is always 'info'
		console.log(logger.level)
	});
program.parse(process.argv);

Expected behavior
My expectation was, that running the cli with the -v/--verbose flag would set the level to debug

Environment informations (please complete the following information):

  • OS: Mac
  • Shell: bash
  • Caporal version: 1.3.0

Additional context
If my suggestion was wrong, could you please tell me how to detect the -v/--verbose flag ?

@jhorbulyk
Copy link
Contributor

It looks like the logging level is set on each of the loggers transports but not on the logger itself:

Caporal.js/lib/program.js

Lines 185 to 188 in db19813

_changeLogLevel(level) {
const logger = this.logger();
Object.keys(logger.transports).forEach(t => logger.transports[t].level = level)
}

@karlitos
Copy link
Author

Many thanks for your reply. But I don't fully understand what does it mean regarding my intention to detect the global verbose settings. I realized I can get the debug/info flog from logger.transports.caporal.level, but is it a good/recommended way of doing it ?

@karlitos
Copy link
Author

Hi, may I ask if there will be any further development regarding the setting the log level on the logger or whether I shall use logger.transports.caporal.level ?

@mattallty
Copy link
Owner

Hey there - I've released beta of the next Caporal (v2). The v2 is a full rewrite of Caporal in Typescript. This issue should be addressed in v2.

Be warned that, while most of the usage remain the same, the v2 is not backward compatible with v1.

You can test it with npm install @caporal/core@beta

Feel free to open issues regarding v2. I would also be happy if you have any feedbacks / suggestions.

@karlitos
Copy link
Author

I can confirm, that v2 version solved my problem, I updated my project to use caporal v2 and so far - so good

@mattallty
Copy link
Owner

Great news - what is the v2 version you're using ?

@mattallty
Copy link
Owner

I'm planning to release a stable version for v2 - But I don't have a lot of feedbacks so far

@karlitos
Copy link
Author

Great news - what is the v2 version you're using ?

"@caporal/core": "^2.0.0-beta.2",

@mattallty
Copy link
Owner

mattallty commented Jun 15, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants