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

[cli] Don't log to STDOUT if debug flags are set #474

Merged
merged 2 commits into from
Aug 20, 2018

Conversation

devplayer0
Copy link
Contributor

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: master, 3.1.x, 4.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

It makes sense that error messages should be written to STDERR and
all others should be written to STDOUT (as shown in #207). However, it
would be convenient to parse the debugging output when the relevant
flags are set.

This change will disable logging to STDOUT and redirect all log messages
to STDERR when any of the debug flags are set. (Resolves #473)

@wing328
Copy link
Member

wing328 commented Jul 18, 2018

@devplayer0 thanks for the PR. Shall we let the users control the behavior using 1>&2 instead so that the users have the option to decide where the log messages go?

@devplayer0
Copy link
Contributor Author

@wing328 Normally that's what I'd do, but the problem is that there's no way to filter out the log output from the JSON when flags like -DdebugOperations are set.

With this change, I can do java -DdebugModels -jar openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java -i cellar.json -o /tmp/cellar > generate.json and the contents generate.json will be parsed correctly by a JSON viewer, while the log messages will be printed to STDERR.

@jimschubert
Copy link
Member

I think this is a good solution, but I think it would make more sense to put this behind an opt-in switch on the command line (something like --debug-to-stdout or --debug-print-only).

I use the debug options often, and while I understand the use case… I would find it annoying to not see the other STDOUT messages when using the debug options.

It makes sense that error messages should be written to STDERR and
all others should be written to STDOUT (as shown in OpenAPITools#207). However, it
would be convenient to parse the debugging output when the relevant
flags are set.

This change will disable logging to STDOUT and redirect all log messages
to STDERR when any of the debug flags are set. (Resolves OpenAPITools#473)
Instead of automatically redirecting log messages to STDERR upon
detection of the debug options, a new command line option
(`--log-to-stderr`) will trigger this behavour, allowing the user to
decide whether or not this is something they want.
@devplayer0
Copy link
Contributor Author

@wing328 @jimschubert I have changed the behaviour so that log messages will only be redirected to STDERR if the --log-to-stderr flag is set. (Instead of just checking for the presence of the debug options)

For example, see the following commands:

java -DdebugModels -jar openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java -i cellar.json -o /tmp/cellar > generate.log
java -DdebugModels -jar openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate --log-to-stderr -g java -i cellar.json -o /tmp/cellar > generate.json

The contents of generate.log would be all (non-error) log messages alongside the JSON output of the debug options as normal. generate.json would contain only the debug options output. (with all log messages being written to STDERR)

@jimschubert
Copy link
Member

I've removed the breaking change label, as this is now a new option with no breaking change.

Copy link
Member

@jimschubert jimschubert left a comment

Choose a reason for hiding this comment

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

Looks good. No longer a breaking change, which is awesome.

I'll merge and update the README separately to list the new option.

@@ -199,8 +202,23 @@
description = "Skips the default behavior of validating an input specification.")
private Boolean skipValidateSpec;

@Option(name = {"--log-to-stderr"},
Copy link
Member

Choose a reason for hiding this comment

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

I think this option is much clearer, and has the benefit of not being a breaking change.

@jimschubert jimschubert merged commit bd7c9e3 into OpenAPITools:master Aug 20, 2018
@jimschubert
Copy link
Member

Updated README via a3e5edc

@devplayer0 devplayer0 deleted the debug-log-stderr branch August 20, 2018 13:10
jimschubert added a commit that referenced this pull request Aug 21, 2018
* master:
  Fix problems in typescript jquery generator (#801)
  [PHP] Add gitignore to AbstractPhpCodegen (#765)
  Improve documentation for usage of a generator in an other jar (#817)
  Improve Symfony 4.1 compatibility (#830)
  📝 Updating 'help generate' switches in README
  [cli] Don't log to STDOUT if debug flags are set (#474)
  [gradle-plugin] README notes on multiple specs (#847)
  Added server variable support (#816)
  fix erlang optiona/required parameters (#829)
  [Java][Rest-assured] Fix generated javadoc and "swagger-annotations" improvement (#831)
@wing328
Copy link
Member

wing328 commented Jan 2, 2019

@devplayer0 thanks for the contribution, which has been included in the 4.0.0-beta release: https://twitter.com/oas_generator/status/1079727020374806529.

Happy New Year and looking forward to more collaboration and contributions in 2019!

A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this pull request Feb 27, 2019
It makes sense that error messages should be written to STDERR and
all others should be written to STDOUT (as shown in OpenAPITools#207). However, it
would be convenient to parse the debugging output when the relevant
flags are set.

This change will disable logging to STDOUT and redirect all log messages
to STDERR when any of the debug flags are set. (Resolves OpenAPITools#473)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants