Skip to content

Commit

Permalink
sample how to combine SetLogTracer and flag.Parse to have runtime flags
Browse files Browse the repository at this point in the history
  • Loading branch information
lainio committed Feb 16, 2024
1 parent c7fec26 commit 1bff1fc
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions samples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"flag"
"log"
"os"

"github.com/lainio/err2"
)
Expand All @@ -12,6 +13,11 @@ var (
isErr = flag.Bool("err", false, "tells if we want to have an error")
)

func init() {
// highlight that this is before flag.Parse to allow it to work properly.
err2.SetLogTracer(os.Stderr)
}

func main() {
defer err2.Catch(err2.Stderr)
log.SetFlags(log.Lshortfile | log.LstdFlags)
Expand Down

0 comments on commit 1bff1fc

Please sign in to comment.