-
https://github.com/uber-go/guide/blob/master/style.md#exit-once The guide recommend to use func main() {
if err := run(); err != nil {
log.Fatal(err)
}
} However, should I try to init my custom logger before I call the Or, is the action 'use my custom logger to log the error' unnecessary to do in the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
@tzq0301 The example uses log.Fatal because that's what most folks already use when they exit multiple times.
The guidance doesn't aim to be prescriptive about logger/program setup. Its main thing is only that you should have exactly one place in your program |
Beta Was this translation helpful? Give feedback.
@tzq0301 The example uses log.Fatal because that's what most folks already use when they exit multiple times.
You have a couple options for
main
, since the purpose of that specific exit it just to print to stderr and exit:Use
log.Fatal
. If you want that to not print timestamps, etc. you can do:Print directly to stderr:
Send the exit code back from
run()
,which uses a custom logger: