This repository has been archived by the owner on Mar 24, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ship should generate a debug log file on every run
What I Did ------------ Cause ship to generate a debug log file on every run, and preserve it in case of failures. (Resolves #400) ``` $ ship init not-a-chart Reading not-a-chart ... Determining application type ... There was an unexpected error! resolve release: determine type of not-a-chart: fetch chart with helm: : Non-absolute URLs should be in form of repo_name/path_to_chart, got: not-a-chart There was an error configuring the application. A debug log has been written to ".ship/debug.log", please include it in any support inquiries. ``` ``` $ cat .ship/debug.log | tail -n 3 | jq . { "caller": "github.com/replicatedhq/ship/vendor/github.com/go-kit/kit/log/level/level.go", "event": "shutdown.commence", "level": "info", "ts": "2018-08-20T19:47:09.238656358Z", "waitTime": "1s" } { "caller": "github.com/replicatedhq/ship/vendor/github.com/go-kit/kit/log/level/level.go", "event": "shutdown.complete", "level": "info", "ts": "2018-08-20T19:47:10.312992803Z" } { "caller": "github.com/replicatedhq/ship/vendor/github.com/go-kit/kit/log/level/level.go", "errorWithStack": "Non-absolute URLs should be in form of repo_name/path_to_chart, got: not-a-chart\nfetch chart with helm: \ngithub.com/replicatedhq/ship/pkg/specs/apptype.(*inspector).DetermineApplicationType\n\t/Users/dex/go/src/github.com/replicatedhq/ship/pkg/specs/apptype/determine_type.go:106\ngithub.com/replicatedhq/ship/pkg/specs.(*Resolver).ResolveRelease\n\t/Users/dex/go/src/github.com/replicatedhq/ship/pkg/specs/interface.go:33\ngithub.com/replicatedhq/ship/pkg/ship.(*Ship).Init\n\t/Users/dex/go/src/github.com/replicatedhq/ship/pkg/ship/kustomize.go:169\ngithub.com/replicatedhq/ship/pkg/ship.(*Ship).InitAndMaybeExit\n\t/Users/dex/go/src/github.com/replicatedhq/ship/pkg/ship/kustomize.go:24\ngithub.com/replicatedhq/ship/pkg/cli.Init.func1\n\t/Users/dex/go/src/github.com/replicatedhq/ship/pkg/cli/init.go:32\ngithub.com/replicatedhq/ship/vendor/github.com/spf13/cobra.(*Command).execute\n\t/Users/dex/go/src/github.com/replicatedhq/ship/vendor/github.com/spf13/cobra/command.go:698\ngithub.com/replicatedhq/ship/vendor/github.com/spf13/cobra.(*Command).ExecuteC\n\t/Users/dex/go/src/github.com/replicatedhq/ship/vendor/github.com/spf13/cobra/command.go:783\ngithub.com/replicatedhq/ship/vendor/github.com/spf13/cobra.(*Command).Execute\n\t/Users/dex/go/src/github.com/replicatedhq/ship/vendor/github.com/spf13/cobra/command.go:736\ngithub.com/replicatedhq/ship/pkg/cli.Execute\n\t/Users/dex/go/src/github.com/replicatedhq/ship/pkg/cli/root.go:82\nmain.main\n\t/Users/dex/go/src/github.com/replicatedhq/ship/cmd/ship/main.go:6\nruntime.main\n\t/Users/dex/homebrew/Cellar/go/1.10.3/libexec/src/runtime/proc.go:198\nruntime.goexit\n\t/Users/dex/homebrew/Cellar/go/1.10.3/libexec/src/runtime/asm_amd64.s:2361\ndetermine type of not-a-chart\ngithub.com/replicatedhq/ship/pkg/specs.(*Resolver).ResolveRelease\n\t/Users/dex/go/src/github.com/replicatedhq/ship/pkg/specs/interface.go:35\ngithub.com/replicatedhq/ship/pkg/ship.(*Ship).Init\n\t/Users/dex/go/src/github.com/replicatedhq/ship/pkg/ship/kustomize.go:169\ngithub.com/replicatedhq/ship/pkg/ship.(*Ship).InitAndMaybeExit\n\t/Users/dex/go/src/github.com/replicatedhq/ship/pkg/ship/kustomize.go:24\ngithub.com/replicatedhq/ship/pkg/cli.Init.func1\n\t/Users/dex/go/src/github.com/replicatedhq/ship/pkg/cli/init.go:32\ngithub.com/replicatedhq/ship/vendor/github.com/spf13/cobra.(*Command).execute\n\t/Users/dex/go/src/github.com/replicatedhq/ship/vendor/github.com/spf13/cobra/command.go:698\ngithub.com/replicatedhq/ship/vendor/github.com/spf13/cobra.(*Command).ExecuteC\n\t/Users/dex/go/src/github.com/replicatedhq/ship/vendor/github.com/spf13/cobra/command.go:783\ngithub.com/replicatedhq/ship/vendor/github.com/spf13/cobra.(*Command).Execute\n\t/Users/dex/go/src/github.com/replicatedhq/ship/vendor/github.com/spf13/cobra/command.go:736\ngithub.com/replicatedhq/ship/pkg/cli.Execute\n\t/Users/dex/go/src/github.com/replicatedhq/ship/pkg/cli/root.go:82\nmain.main\n\t/Users/dex/go/src/github.com/replicatedhq/ship/cmd/ship/main.go:6\nruntime.main\n\t/Users/dex/homebrew/Cellar/go/1.10.3/libexec/src/runtime/proc.go:198\nruntime.goexit\n\t/Users/dex/homebrew/Cellar/go/1.10.3/libexec/src/runtime/asm_amd64.s:2361\nresolve release\ngithub.com/replicatedhq/ship/pkg/ship.(*Ship).Init\n\t/Users/dex/go/src/github.com/replicatedhq/ship/pkg/ship/kustomize.go:171\ngithub.com/replicatedhq/ship/pkg/ship.(*Ship).InitAndMaybeExit\n\t/Users/dex/go/src/github.com/replicatedhq/ship/pkg/ship/kustomize.go:24\ngithub.com/replicatedhq/ship/pkg/cli.Init.func1\n\t/Users/dex/go/src/github.com/replicatedhq/ship/pkg/cli/init.go:32\ngithub.com/replicatedhq/ship/vendor/github.com/spf13/cobra.(*Command).execute\n\t/Users/dex/go/src/github.com/replicatedhq/ship/vendor/github.com/spf13/cobra/command.go:698\ngithub.com/replicatedhq/ship/vendor/github.com/spf13/cobra.(*Command).ExecuteC\n\t/Users/dex/go/src/github.com/replicatedhq/ship/vendor/github.com/spf13/cobra/command.go:783\ngithub.com/replicatedhq/ship/vendor/github.com/spf13/cobra.(*Command).Execute\n\t/Users/dex/go/src/github.com/replicatedhq/ship/vendor/github.com/spf13/cobra/command.go:736\ngithub.com/replicatedhq/ship/pkg/cli.Execute\n\t/Users/dex/go/src/github.com/replicatedhq/ship/pkg/cli/root.go:82\nmain.main\n\t/Users/dex/go/src/github.com/replicatedhq/ship/cmd/ship/main.go:6\nruntime.main\n\t/Users/dex/homebrew/Cellar/go/1.10.3/libexec/src/runtime/proc.go:198\nruntime.goexit\n\t/Users/dex/homebrew/Cellar/go/1.10.3/libexec/src/runtime/asm_amd64.s:2361", "event": "exit.withErr", "level": "warn", "ts": "2018-08-20T19:47:10.313454242Z" } ``` How I Did it ------------ - add new type `compositeLogger` that implements `log.Logger` by forwarding down to any number of delegate loggers - `logger.New()` tries to create a file at `.ship/debug.log`, and add a `debugLogger` that writes to that file at debug level, regardless of the configured `log-level` - `logger.New()` returns a compositeLogger that combines the stdout and debug loggers. Fails silently if it can't open the file. - `pkg/ship/exit.go` will now message about the location of the log file if we were able to create it, rather than requesting a re-run with `--log-level=debug` - Cobra deletes `.ship/debug.log` on successful exit Not directly related: - move `ExitWithXXX` methods and their helpers into `pkg/ship/exit.go` How to verify it ------------ Run `ship init not-a-chart`, see new messaging and inspect debug log. It looks nice when piped to `jq`: ``` cat .ship/debug.log | jq . ``` Description for the Changelog ------------ Ship will provide a debug log file on failures to aid in troubleshooting any issues. ![](https://upload.wikimedia.org/wikipedia/commons/thumb/7/75/New_Carissa_Shipwreck_%2823428021605%29.jpg/1920px-New_Carissa_Shipwreck_%2823428021605%29.jpg)
- Loading branch information