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

cmd/hc-install: Enable logging into a file #193

Merged
merged 2 commits into from
Apr 5, 2024
Merged

Conversation

radeksimko
Copy link
Member

A few times in the past and recently I found myself struggling to answer some detailed questions about what exactly happens during the installation and why an installation may be failing.

I think opt-in logging can help understand what's going and aid debugging.

Example

$ go run ./cmd/hc-install install -log-file=/dev/stderr -version 1.0.0 terraform
hc-install: will install terraform@1.0.0
[DEBUG] 2024/04/04 10:25:18.133986 exact_version.go:103: will install into dir at /Users/radeksimko/gopath/src/github.com/hashicorp/hc-install
[DEBUG] 2024/04/04 10:25:18.134274 releases.go:131: requesting version from https://releases.hashicorp.com/terraform/1.0.0/index.json
[DEBUG] 2024/04/04 10:25:18.223458 releases.go:154: received 200 OK
failed to install terraform@1.0.0: no ZIP archive found for terraform <nil> darwin/arm64
exit status 1
$ go run ./cmd/hc-install install -log-file=./foo.log -version 1.1.0 terraform
hc-install: will install terraform@1.1.0
installed terraform@1.1.0 to /Users/radeksimko/gopath/src/github.com/hashicorp/hc-install/terraform

$ cat foo.log
[DEBUG] 2024/04/04 10:26:02.230453 exact_version.go:103: will install into dir at /Users/radeksimko/gopath/src/github.com/hashicorp/hc-install
[DEBUG] 2024/04/04 10:26:02.230856 releases.go:131: requesting version from https://releases.hashicorp.com/terraform/1.1.0/index.json
[DEBUG] 2024/04/04 10:26:02.395232 releases.go:154: received 200 OK
[DEBUG] 2024/04/04 10:26:02.403076 checksum_downloader.go:60: downloading signature from https://releases.hashicorp.com/terraform/1.1.0/terraform_1.1.0_SHA256SUMS.72D7468F.sig
[DEBUG] 2024/04/04 10:26:02.484267 checksum_downloader.go:81: downloading checksums from https://releases.hashicorp.com/terraform/1.1.0/terraform_1.1.0_SHA256SUMS
[DEBUG] 2024/04/04 10:26:02.581662 checksum_downloader.go:149: checksum signature is valid
[DEBUG] 2024/04/04 10:26:02.581853 downloader.go:82: downloading archive from https://releases.hashicorp.com/terraform/1.1.0/terraform_1.1.0_darwin_arm64.zip
[DEBUG] 2024/04/04 10:26:02.667995 downloader.go:116: copying "terraform_1.1.0_darwin_arm64.zip" (19491369 bytes) to /var/folders/9w/pddq2x656j76vxvsbhcs4nwr0000gq/T/terraform_1.1.0_darwin_arm64.zip3633819228
[DEBUG] 2024/04/04 10:26:02.668127 downloader.go:120: verifying checksum of "terraform_1.1.0_darwin_arm64.zip"
[DEBUG] 2024/04/04 10:26:03.345805 downloader.go:143: copied 19491369 bytes to /var/folders/9w/pddq2x656j76vxvsbhcs4nwr0000gq/T/terraform_1.1.0_darwin_arm64.zip3633819228
[DEBUG] 2024/04/04 10:26:03.346679 downloader.go:175: unpacking terraform to /Users/radeksimko/gopath/src/github.com/hashicorp/hc-install
[DEBUG] 2024/04/04 10:26:03.657731 exact_version.go:148: changing perms of /Users/radeksimko/gopath/src/github.com/hashicorp/hc-install/terraform

@radeksimko radeksimko added the enhancement New feature or request label Apr 4, 2024
Copy link
Member

@bschaatsbergen bschaatsbergen left a comment

Choose a reason for hiding this comment

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

This is a great addition 👍🏼, I think it would be a good idea to consider a -log-stdout flag too, what do you think?

@radeksimko
Copy link
Member Author

I think it would be a good idea to consider a -log-stdout flag too, what do you think?

I don't disagree but I think it's basically a syntactic sugar at this point. We already allow logging to stdout or stderr, as shown in the example above with /dev/stderr - similar one can be crafted with /dev/stdout.

It is true though that this may not be as obvious to people and also that this may only work on Unix based systems.

All that said - I think we can still introduce this flag in a separate PR.

@radeksimko radeksimko merged commit 8093f09 into main Apr 5, 2024
11 checks passed
@radeksimko radeksimko deleted the f-cmd-file-logging branch April 5, 2024 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants