-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlog.go
45 lines (36 loc) · 754 Bytes
/
log.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package fsdup
import (
"fmt"
"log"
"strings"
)
var (
Debug = false // Toggle with -debug CLI flag! // TODO fix this with debug/log levels
Quiet = false // TODO fix this with log levels
statusLastLength = 0
)
func debugf(format string, args ...interface{}) {
if Quiet {
return
}
if Debug {
log.Printf(format, args...)
}
}
func statusf(format string, args ...interface{}) {
if Quiet {
return
}
if Debug {
fmt.Printf(format + "\n", args...)
} else {
status := fmt.Sprintf(format, args...)
statusNewLength := len(status)
if statusNewLength < statusLastLength {
fmt.Printf("\r%s\r%s", strings.Repeat(" ", statusLastLength), status)
} else {
fmt.Printf("\r%s", status)
}
statusLastLength = statusNewLength
}
}