Skip to content

Improve output format #32

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

Merged
merged 17 commits into from
Sep 13, 2021
Merged

Improve output format #32

merged 17 commits into from
Sep 13, 2021

Conversation

polldo
Copy link
Contributor

@polldo polldo commented Sep 8, 2021

Motivation

  • Allows users to choose an output format between text and json
  • Writes to stdout (through fmt.Print..) have been replaced into writes to a logger. If the verbose flag -v is passed to the command line, then the logger will be enabled. Otherwise, all the logs messages will be discarded.

These changes allow users to save results in files. For example, with the following command, a device is provisioned and its properties are written into a json file:
./iot-cloud-cli device create --format json --name <deviceName> > deviceName.json

Change description

Additional Notes

Reviewer checklist

  • PR address a single concern.
  • PR title and description are properly filled.
  • Changes will be merged in main.
  • Changes are covered by tests.
  • Logging is meaningful in case of troubleshooting.
  • History is clean, commit messages are meaningful (see CONTRIBUTING.md) and are well formatted.

Copy link
Contributor

@glumia glumia left a comment

Choose a reason for hiding this comment

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

Hey, I read the changes up to cli/thing/list.go and stopped there because I noticed one main issue: we need to define clearly what we want on stderr and what on stdout and rework the feedback/logs.

We can't just move everything that precedently was printed to stdout to logs, in this way we will stop giving useful feedbacks to users and litter logs with unuseful messages.

Not printing anything to stdout in case of success could be fine if we decide to commit to a "quiet on success/verbose on error" behavior, but in this case we need to be coherent with it on all commands.

On the other hand, stderr (logs) should be used only to print information that could be useful for debugging purposes, because one does not reach for them unless there's some problem.

Update: check below. I missed an important detail about logs not being printed to stderr if the -v is not provided. In our case it makes sense to have detailed logs of what happens.

@polldo
Copy link
Contributor Author

polldo commented Sep 10, 2021

@glumia
Thanks a lot for the feedbacks

Not printing anything to stdout in case of success could be fine if we decide to commit to a "quiet on success/verbose on error" behavior, but in this case, we need to be coherent with it on all commands.

Yes, this was my goal. In this way the user can save the output of the commands into a file (when it makes sense).
So the behavior should be:

  • in case of success without -v flag, print only the useful "data" that the user could save in a file (for example a newly created thing)
  • in case of success with -v flag, print everything. here the user cannot expect to save the result in a file without having them "dirtied" by the logs.
  • in case of error print the error

Have I not been coherent with it on all commands?

@glumia
Copy link
Contributor

glumia commented Sep 10, 2021

Yes! Sorry I got confused by the default behaviour of discarding logs and of -v both enabling logging and redirecting it to stdout. I had in my mind the classic behaviour of unix tools that always print logs to stderr and normal output to stdout.

Your reasoning makes perfectly sense 👍

As we were talking about in our call we need to just to remove logs when there's already the output of feedbacks and to standardize the formatting of results as text.

@polldo polldo requested a review from glumia September 10, 2021 18:34
@polldo polldo merged commit 423ed85 into main Sep 13, 2021
@polldo polldo deleted the polldo/format-output branch September 13, 2021 08:34
@polldo polldo mentioned this pull request Sep 15, 2021
6 tasks
polldo added a commit that referenced this pull request Sep 2, 2022
Allows users to choose an output format between text and json.
Writes to stdout (through fmt.Print..) have been replaced into writes to a logger. If the verbose flag -v is passed to the command line, then the logger will be enabled. Otherwise, all the logs messages will be discarded.

These changes allow users to save results in files. For example, with the following command, a device is provisioned and its properties are written into a json file:
./iot-cloud-cli device create --format json --name <deviceName> > deviceName.json

* Replace fmt print into log info

* Distinguish board from device

* Improve device format output

* Fix log infof

* Improve logs of arduino-cli

This commit has two effects:
- arduino-cli init command logs are masked out.
- arduino-cli upload logs are logged only if logrus was already enabled.

* Fix log msg

* Update go mod

* Improve thing output format

* Refactor thing output format

* Fix device iot client

* Improve errors: use stderr and error codes

* cli package: don't return error

* Remove unreachable code

* Improve log initialization

* Remove duplication of info messages

* Add arduino-cli source to upload logs

* Return consistent output
polldo added a commit that referenced this pull request Sep 2, 2022
Allows users to choose an output format between text and json.
Writes to stdout (through fmt.Print..) have been replaced into writes to a logger. If the verbose flag -v is passed to the command line, then the logger will be enabled. Otherwise, all the logs messages will be discarded.

These changes allow users to save results in files. For example, with the following command, a device is provisioned and its properties are written into a json file:
./iot-cloud-cli device create --format json --name <deviceName> > deviceName.json


* Replace fmt print into log info

* Distinguish board from device

* Improve device format output

* Fix log infof

* Improve logs of arduino-cli

This commit has two effects:
- arduino-cli init command logs are masked out.
- arduino-cli upload logs are logged only if logrus was already enabled.

* Fix log msg

* Update go mod

* Improve thing output format

* Refactor thing output format

* Fix device iot client

* Improve errors: use stderr and error codes

* cli package: don't return error

* Remove unreachable code

* Improve log initialization

* Remove duplication of info messages

* Add arduino-cli source to upload logs

* Return consistent output
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.

3 participants