Skip to content

Commit 1bff1fc

Browse files
committed
sample how to combine SetLogTracer and flag.Parse to have runtime flags
1 parent c7fec26 commit 1bff1fc

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

samples/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"flag"
55
"log"
6+
"os"
67

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

16+
func init() {
17+
// highlight that this is before flag.Parse to allow it to work properly.
18+
err2.SetLogTracer(os.Stderr)
19+
}
20+
1521
func main() {
1622
defer err2.Catch(err2.Stderr)
1723
log.SetFlags(log.Lshortfile | log.LstdFlags)

0 commit comments

Comments
 (0)