-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
70 lines (59 loc) · 1.43 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
68
69
70
package optic
import (
"fmt"
"strings"
)
const (
colorReset = "\033[0m"
colorRed = "\033[31m"
colorGreen = "\033[32m"
colorYellow = "\033[33m"
colorCyan = "\033[36m"
colorViolet = "\033[35m"
colorBlue = "\033[34m"
colorWhite = "\033[37m"
colorReverse = "\033[7m"
)
func serving(port string) {
msg := fmt.Sprintf("%s(o)ptic%s watching on: %s", colorReverse, colorReset, port)
fmt.Println(msg)
sz := 21 + len(port)
for i := 0; i < sz; i++ {
fmt.Print("-")
}
fmt.Print("\n")
}
func optic() string {
return fmt.Sprintf("%s(o)%s", colorReverse, colorReset)
}
func colorReversePrint(tag string, message string, color string) {
fmt.Println(fmt.Sprintf("%s%s%s %s %s %s", optic(), colorReverse, color, tag, colorReset, message))
}
func green(tag string, message string) {
colorReversePrint(tag, message, colorGreen)
}
func cyan(tag string, message string) {
colorReversePrint(tag, message, colorCyan)
}
func yellow(tag string, message string) {
colorReversePrint(tag, message, colorYellow)
}
func violet(tag string, message string) {
colorReversePrint(tag, message, colorViolet)
}
func reflected(code int, path string) {
var (
status = fmt.Sprintf("%d", code)
color = colorGreen
)
if len(status) > 0 {
switch status[0] {
case '4':
color = colorYellow
case '5':
color = colorRed
}
}
path = "/" + strings.Replace(path, base.String(), "", 1)
colorReversePrint(fmt.Sprintf("%d", code), path, color)
}