Skip to content

Conversation

@shaunn
Copy link

@shaunn shaunn commented Feb 20, 2023

Background: When making changes that may affect multiple components/clusters having the generate fail deadly has become personally an issue when attempting to get an overview of what problems exist past the one that fatally exited.

Two arguments --noexit and --long are introduced; the first to stop the program from exiting during a fatal or panic event, and the second to print error messages in a multi-line readable format.

Build params:

  • go version go1.19.6 darwin/amd64
Example of how a run with a fatal error works, just as before

kr8gen

A generate with the --long flag showing multi-line print of the error (fmt.Println(err)) for the humans before immediately exiting

kr8gen_long

A generate with the --noexit flag demonstrating that fatal errors do not exit and all runs attempt to continue

kr8gen_noexit

A generate with the --noexit and --long flags together demonstrating that fatal errors do not exit and all runs attempt to continue AND all errors printed in human readable format

kr8gen_noexit_long

Updated --long

long_output

@shaunn shaunn force-pushed the logging branch 3 times, most recently from 2f5e42f to 1147fd9 Compare February 20, 2023 14:11
@cspargo-apptio
Copy link
Collaborator

zerolog already has a facility for this to append custom output

        log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr, NoColor: !colorOutput,
                FormatExtra: func(evt map[string]interface{}, buf *bytes.Buffer) error {
                        if errstring, ok := evt["error"]; ok {
                                buf.WriteString("\n" + fmt.Sprint(errstring))
                        }
                        return nil
                },
        })

@shaunn
Copy link
Author

shaunn commented Feb 20, 2023

@cspargo-apptio Yes, thank you! I was tripped up on this. Works perfectly!

@shaunn shaunn changed the title WIP:Logging enhancements Logging enhancements Jun 11, 2023
@srosenberg-apptio
Copy link

I would close this if I could

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.

4 participants