-
Notifications
You must be signed in to change notification settings - Fork 16
/
format.go
62 lines (53 loc) · 1.24 KB
/
format.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
package logger
import (
"fmt"
"sync"
)
var (
colors sync.Map
white = "\033[37m"
reset = "\033[0m"
bold = "\033[1m"
red = "\033[31m"
blue = "\033[34m"
green = "\033[32m"
cyan = "\033[36m"
yellow = "\033[33m"
magenta = "\033[35m"
//colorIndex = 0
//listOfColors sync.Map
//colorLoggerDict sync.Map
/*colors = []string{
"\033[34m", // blue
"\033[32m", // green
"\033[36m", // cyan
"\033[33m", // yellow
"\033[35m", // magenta
}*/
)
func init() {
colors.Store("index", 0)
colors.Store("index:0", blue)
colors.Store("index:1", green)
colors.Store("index:2", cyan)
colors.Store("index:3", yellow)
colors.Store("index:4", magenta)
colors.Store("len", 5)
}
func nextColor() string {
//colorIndex = colorIndex + 1
//return colors[colorIndex%len(colors)]
currentIndex, _ := colors.Load("index")
len, _ := colors.Load("len")
color, _ := colors.Load(fmt.Sprintf("index:%d", currentIndex.(int)%len.(int)))
colors.Store("index", currentIndex.(int)+1)
return color.(string)
}
func colorFor(key string) string {
if color, ok := colors.Load(fmt.Sprintf("module:%s", key)); ok {
return color.(string)
}
color := nextColor()
colors.Store(fmt.Sprintf("module:%s", key), color)
return color
}