-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.go
67 lines (54 loc) · 1.18 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package aliyun
import (
"fmt"
"github.com/fatih/color"
)
var (
green = color.New(color.FgGreen).SprintFunc()
yellow = color.New(color.FgYellow).SprintFunc()
red = color.New(color.FgRed).SprintFunc()
)
type ProgressTracker struct {
state int
}
func NewProgressTracker() *ProgressTracker {
return &ProgressTracker{state: 0}
}
func (p *ProgressTracker) Info(format string, a ...interface{}) {
b := []interface{}{green("INFO")}
b = append(b, a...)
if p.state > 0 {
fmt.Printf("\033[1A\033[100D")
}
var v string
switch p.state % 4 {
case 0:
v = "|"
case 1:
v = "/"
case 2:
v = "-"
case 3:
v = "\\"
}
fmt.Printf("[%s ] "+format+" "+v+"\n", b...)
p.state++
}
func Text(format string, a ...interface{}) {
fmt.Printf(format+"\n", a...)
}
func Info(format string, a ...interface{}) {
b := []interface{}{green("INFO")}
b = append(b, a...)
fmt.Printf("[%s ] "+format+"\n", b...)
}
func Warn(format string, a ...interface{}) {
b := []interface{}{yellow("WARN")}
b = append(b, a...)
fmt.Printf("[%s ] "+format+"\n", b...)
}
func Error(format string, a ...interface{}) {
b := []interface{}{yellow("ERROR")}
b = append(b, a...)
fmt.Printf("[%s] "+format+"\n", b...)
}