github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/examples/trace_logging/main.go (about) 1 package main 2 3 import ( 4 "github.com/v2pro/plz/countlog" 5 "errors" 6 ) 7 8 // when using --tags release, countlog.Trace will be empty and optimized away 9 //go:noinline 10 func trace_should_be_optimized_away() { 11 countlog.Trace("event!trace can be optimized", "key", "value") 12 } 13 14 // if err != nil will not be checked twice when inlined 15 //go:noinline 16 func trace_call_should_combine_the_error_checking() int { 17 err := doSomething() 18 countlog.TraceCall("callee!doSomething", err) 19 if err != nil { 20 return 1 21 } 22 return 0 23 } 24 25 func doSomething() error { 26 return errors.New("abc") 27 } 28 29 func main() { 30 countlog.SetMinLevel(countlog.LevelTrace) 31 trace_should_be_optimized_away() 32 trace_call_should_combine_the_error_checking() 33 }