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

Respect desired logLevel #225

Merged
merged 6 commits into from
Mar 8, 2018
Merged

Conversation

marstr
Copy link
Member

@marstr marstr commented Mar 8, 2018

@marstr
Copy link
Member Author

marstr commented Mar 8, 2018

@amarzavery, @olydis please take a look :)

It seems like I'm not a "Contributor" here, so I can't straight up request a review from you in GitHub UI.

lib/validate.js Outdated
log.info('No Errors were found.');
log.consoleLogLevel = consoleLevel;
}
log.info('No Errors were found.');
Copy link

@olydis olydis Mar 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know this code at all, but the fact that it was guarded by log.consoleLogLevel === 'json' makes me fear that automation may try to parse the output of this script as JSON. Or will this message not appear on stdout for some reasons I'm unaware of? (like the arg you added in package.json)

Copy link
Member Author

@marstr marstr Mar 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way I read this block, it was overwriting the desired consoleLogLevel in any case except for json and off. By removing the check, it should never overwrite the specified consoleLogLevel, including json and off. I may be dumb though, let me know if I've messed up mentally applying DeMorgans law :)

Copy link
Member Author

@marstr marstr Mar 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errr, I guess I'm making the assumption that whatever is converting stdout to JSON can handle a message it wouldn't have seen before. I'm also assuming that consoleLogLevel off knows to totally disregard things printed to info. I guess the safest way to handle this would be to just keep that check there, with the chance that it adds a little redundancy.

I'll add the check back to be safe.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in cases where someone set the log level to error then they do not see anything on the command prompt when running oav manually. Folks said they did not know if everything was ok. Hence I did the above thing to explicitly say that "No errors were found." 👍 .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error is above info in the log level severity...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks for the context, @amarzavery. With my PR in the specs repository to use the "min" mocha reporter, it should clear that up without needing to print the "No errors were found." message.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But your usecase is genuine. While running this as a script you don't need that info statement.
We can have a variable named mode that can tell us how oav is being used. If the mode is cli then we can display the log.info(..) statement. If it is script then we can choose to not log that statement.

If you are writing a script then the entry point is via the file indicated in "main" property of package.json. For cli it is the bin property https://github.com/Azure/oav/blob/master/package.json#L49-L52

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can export a variable here in lib/validate.js called exports.isCliMode = true; (We assume that folks would be running oav as a CLI).
Then in index.js over here validate.isCliMode = false;.

if (validator.specValidationResult.validityStatus) {
    if (!(log.consoleLogLevel === 'json' || log.consoleLogLevel === 'off') && exports.isCliMode) {
      let consoleLevel = log.consoleLogLevel;
      log.consoleLogLevel = 'info';
      log.info('No Errors were found.');
      log.consoleLogLevel = consoleLevel;
    }
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, that seems counter-intuitive to me. Maybe a simpler option would be to have the default consoleLogLevel set to 'info'? In my mind anyway, I'd rather have the tool behave consistently regardless of how it was invoked.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. That is a valid point too.

@amarzavery
Copy link
Contributor

Can you also update the version of moment to ^2.21.0 in package.json (the 2.18.1 version has a security vulnerability that was fixed in the newer version).

@amarzavery amarzavery merged commit 3e26942 into Azure:master Mar 8, 2018
@vladbarosan vladbarosan removed the review label Mar 8, 2018
@marstr
Copy link
Member Author

marstr commented Mar 8, 2018

You make me a very happy man, @amarzavery.

@amarzavery
Copy link
Contributor

@marstr - One more thing. Can you please delete the package-lock.json and also delete the node_modules folder and excute npm install again. This should generate a new lock file. Can you please send a PR with that new lock file. The current one still points to 2.18.1 version of moment.

@marstr marstr mentioned this pull request Mar 8, 2018
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

Successfully merging this pull request may close these issues.

4 participants