This repository was archived by the owner on Mar 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole.go
More file actions
93 lines (80 loc) · 1.41 KB
/
console.go
File metadata and controls
93 lines (80 loc) · 1.41 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package log
import (
"encoding/json"
"fmt"
"gopkg.in/yaml.v3"
)
func console_printmap(l int, arg map[string]interface{}) {
switch serializationtype {
case "json":
fallthrough
case "yaml":
console_printjson(l, arg)
case "table":
console_table(arg)
}
}
func console_printstruct(l int, arg Struct) {
switch serializationtype {
case "json":
fallthrough
case "yaml":
//console_printjson(l, arg)
case "table":
//console_table(arg)
}
}
func console_printjson(l int, arg Fields) {
var c Colortext
var pre bool
switch l {
case PRINT:
c = Black
case INFO:
c = Pink
case WARN:
c = Yellow
case ERROR:
c = LightRed
case FATAL:
c = Red
}
s := string(c)
if showtime || l >= WARN {
s = s + arg["_"].(string)
pre = true
}
if showtracefile || l >= WARN {
if t, exist := arg["_trace"]; !exist || t == nil {
} else {
s = s + " " + arg["_trace"].(string)
pre = true
}
}
delete(arg, "_")
delete(arg, "_trace")
var bs []byte
var err error
switch serializationtype {
case "yaml":
bs, err = yaml.Marshal(arg)
default:
bs, err = json.Marshal(arg)
}
if err != nil {
println(err.Error())
}
if pre {
s = s + "\t" + string(bs) + string(EndColor)
} else {
s = s + string(bs) + string(EndColor)
}
fmt.Println(s)
}
func console_table(arg map[string]interface{}) {
bs, err := Fields(arg).TableMarshal()
if err != nil {
println(err.Error())
}
fmt.Println(string(bs))
}