warrensbox / terraform-switcher

A command line tool to switch between different versions of terraform (install with homebrew and more)
https://tfswitch.warrensbox.com
MIT License
1.36k stars 136 forks source link

tfswitch -U logs instead of returning version #505

Closed brainsiq closed 1 month ago

brainsiq commented 1 month ago

There appears to have been a change in the behaviour of tfswitch -U. It now returns a result via logs, which I understand from other issues appears to be a fairly recent change.

This means if you set the log level to error then you get no output at all.

❯ tfswitch -U --log-level=ERROR
❯ tfswitch -U --log-level=INFO
14:42:24.303 INFO 1.9.6

I was using -U to bootstrap new projects with the latest as required_version, which has stopped working, and needs to be updated to instead parse the output. This isn't a big problem but wanted to check if it is intended behaviour?

This also applies to other flags like -S and -P but isn't consistent with -v which returns raw output without logs.

MatthewJohn commented 1 month ago

Hmm, I agree.

I think that if the desired output of an action is purely the output itself, it almost definitely shouldn’t be logged and should just be printed. I wonder whether the logging goes to stdout or stderr! 🤔

Matt

Sent from my iPhone

On 18 Sep 2024, at 15:06, Chris Impey @.***> wrote:

 There appears to have been a change in the behaviour of tfswitch -U. It now returns a result via logs, which I understand from other issues appears to be a fairly recent change.

This means if you set the log level to error then you get no output at all.

❯ tfswitch -U --log-level=ERROR

❯ tfswitch -U --log-level=INFO 14:42:24.303 INFO 1.9.6 This also applies to other flags like -S and -P. Is this intended behaviour?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.

brainsiq commented 1 month ago

I tested that and it's definitely stdout.

tfswitch -U > program.stdout 2> program.stderr

The output is in the stdout file

yermulnik commented 1 month ago

Yep, agree too. Need to reconfigure logging to send to stderr and output to stdout only what's requested for --show-* flags. I wish we've got more contributions as we seem to be stagnating on development again 😢

MatthewJohn commented 1 month ago

@yermulnik @brainsiq I've had a quick go at this in https://github.com/warrensbox/terraform-switcher/pull/506 - let me know what you think :)

brainsiq commented 1 month ago

Sorry for the lack of feedback, but I d/l the latest version of tswitch and the functionality now looks good to me. Not familiar with golang but was able to understand the code change too 👍

yermulnik commented 1 month ago

@brainsiq Thank you for the feedback 👍🏻