mirror of
https://github.com/octoleo/restic.git
synced 2024-11-22 21:05:10 +00:00
debug: Dynamically pad tag in debug log
This commit is contained in:
parent
959da0a76a
commit
813031a989
@ -9,6 +9,7 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
@ -145,6 +146,8 @@ func getPosition() string {
|
|||||||
return fmt.Sprintf("%3d %s:%3d", goroutine, filepath.Base(file), line)
|
return fmt.Sprintf("%3d %s:%3d", goroutine, filepath.Base(file), line)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var maxTagLen = 10
|
||||||
|
|
||||||
func Log(tag string, f string, args ...interface{}) {
|
func Log(tag string, f string, args ...interface{}) {
|
||||||
opts.m.Lock()
|
opts.m.Lock()
|
||||||
defer opts.m.Unlock()
|
defer opts.m.Unlock()
|
||||||
@ -153,7 +156,12 @@ func Log(tag string, f string, args ...interface{}) {
|
|||||||
f += "\n"
|
f += "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
formatString := fmt.Sprintf("[% 25s] %-20s %s", tag, getPosition(), f)
|
if len(tag) > maxTagLen {
|
||||||
|
maxTagLen = len(tag)
|
||||||
|
}
|
||||||
|
|
||||||
|
formatStringTag := "[%" + strconv.FormatInt(int64(maxTagLen), 10) + "s]"
|
||||||
|
formatString := fmt.Sprintf(formatStringTag+" %s %s", tag, getPosition(), f)
|
||||||
|
|
||||||
dbgprint := func() {
|
dbgprint := func() {
|
||||||
fmt.Fprintf(os.Stderr, formatString, args...)
|
fmt.Fprintf(os.Stderr, formatString, args...)
|
||||||
|
Loading…
Reference in New Issue
Block a user