summaryrefslogtreecommitdiff
path: root/lib/textui/log.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-02-28 11:23:27 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-03-02 17:29:27 -0700
commit301a28a093372f1182253d021659425070ae8747 (patch)
tree90113b4c4dac91ea5ad6f4342b45a9b9b2988007 /lib/textui/log.go
parent996137cdfdff9ec6fbb5c93e21d75b21052e01ae (diff)
Shorten the log lines if < LogLevelDebug
Diffstat (limited to 'lib/textui/log.go')
-rw-r--r--lib/textui/log.go44
1 files changed, 23 insertions, 21 deletions
diff --git a/lib/textui/log.go b/lib/textui/log.go
index b4dcea4..2a6fdd4 100644
--- a/lib/textui/log.go
+++ b/lib/textui/log.go
@@ -237,28 +237,30 @@ func (l *logger) log(lvl dlog.LogLevel, writeMsg func(io.Writer)) {
}
// caller //////////////////////////////////////////////////////////////
- const (
- thisModule = "git.lukeshu.com/btrfs-progs-ng"
- thisPackage = "git.lukeshu.com/btrfs-progs-ng/lib/textui"
- maximumCallerDepth int = 25
- minimumCallerDepth int = 3 // runtime.Callers + .log + .Log
- )
- var pcs [maximumCallerDepth]uintptr
- depth := runtime.Callers(minimumCallerDepth, pcs[:])
- frames := runtime.CallersFrames(pcs[:depth])
- for f, again := frames.Next(); again; f, again = frames.Next() {
- if !strings.HasPrefix(f.Function, thisModule+"/") {
- continue
- }
- if strings.HasPrefix(f.Function, thisPackage+".") {
- continue
- }
- if nextField == len(fieldKeys) {
- logBuf.WriteString(" :")
+ if lvl >= dlog.LogLevelDebug {
+ const (
+ thisModule = "git.lukeshu.com/btrfs-progs-ng"
+ thisPackage = "git.lukeshu.com/btrfs-progs-ng/lib/textui"
+ maximumCallerDepth int = 25
+ minimumCallerDepth int = 3 // runtime.Callers + .log + .Log
+ )
+ var pcs [maximumCallerDepth]uintptr
+ depth := runtime.Callers(minimumCallerDepth, pcs[:])
+ frames := runtime.CallersFrames(pcs[:depth])
+ for f, again := frames.Next(); again; f, again = frames.Next() {
+ if !strings.HasPrefix(f.Function, thisModule+"/") {
+ continue
+ }
+ if strings.HasPrefix(f.Function, thisPackage+".") {
+ continue
+ }
+ if nextField == len(fieldKeys) {
+ logBuf.WriteString(" :")
+ }
+ file := f.File[strings.LastIndex(f.File, thisModDir+"/")+len(thisModDir+"/"):]
+ fmt.Fprintf(logBuf, " (from %s:%d)", file, f.Line)
+ break
}
- file := f.File[strings.LastIndex(f.File, thisModDir+"/")+len(thisModDir+"/"):]
- fmt.Fprintf(logBuf, " (from %s:%d)", file, f.Line)
- break
}
// boilerplate /////////////////////////////////////////////////////////