github.com/haraldrudell/parl@v0.4.176/on-debug.go (about) 1 /* 2 © 2023–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/) 3 ISC License 4 */ 5 6 package parl 7 8 const ( 9 debugThunkFrames = 2 // DebugThunk + IsThisDebugN 10 ) 11 12 // OnDebug is similar to parl.Debug but arguments are only resolved when 13 // debug is true, ie. when arguments should actually be printed 14 // - the argument can be a function literal invoking parl.Sprintf 15 // 16 // Usage: 17 // 18 // var x int 19 // parl.OnDebug(func() string { return parl.Sprintf("before: %d", x)}) 20 func OnDebug(invokedIfDebug func() string) { 21 if !IsThisDebugN(debugThunkFrames) { 22 return 23 } 24 stderrLogger.Log(invokedIfDebug()) 25 }