box-o-sand/argh/argh.go

35 lines
507 B
Go
Raw Normal View History

package argh
2022-05-14 00:58:55 +00:00
import (
"fmt"
2022-05-14 00:58:55 +00:00
"log"
"os"
"path/filepath"
"runtime"
2022-05-14 00:58:55 +00:00
)
var (
tracingEnabled = os.Getenv("ARGH_TRACING") == "enabled"
traceLogger *log.Logger
2022-05-14 00:58:55 +00:00
)
func init() {
if !tracingEnabled {
return
}
traceLogger = log.New(os.Stderr, "ARGH TRACING: ", 0)
}
2022-05-14 00:58:55 +00:00
func tracef(format string, v ...any) {
if !tracingEnabled {
return
}
2022-05-29 23:04:31 +00:00
if _, file, line, ok := runtime.Caller(1); ok {
format = fmt.Sprintf("%v:%v ", filepath.Base(file), line) + format
}
traceLogger.Printf(format, v...)
}