@rivascva/dt-idl 1.1.73 → 1.1.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/go/log/log.go +16 -24
- package/go/log/utils.go +4 -1
- package/package.json +1 -1
package/go/log/log.go
CHANGED
|
@@ -21,43 +21,36 @@ type Logger interface {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
type Log struct {
|
|
24
|
-
kvs
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
error *log.Logger
|
|
24
|
+
kvs map[string]any
|
|
25
|
+
info *log.Logger
|
|
26
|
+
warn *log.Logger
|
|
27
|
+
error *log.Logger
|
|
29
28
|
}
|
|
30
29
|
|
|
31
30
|
// NewLog creates a new log.
|
|
32
31
|
func NewLog() *Log {
|
|
33
|
-
return NewLogWithPrefix("")
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// NewLogWithPrefix creates a new log with a custom prefix.
|
|
37
|
-
func NewLogWithPrefix(prefix string) *Log {
|
|
38
32
|
return &Log{
|
|
39
|
-
kvs:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
error: log.New(os.Stdout, "[ERROR] ", log.LstdFlags),
|
|
33
|
+
kvs: make(map[string]any, 10),
|
|
34
|
+
info: log.New(os.Stdout, "", log.LstdFlags),
|
|
35
|
+
warn: log.New(os.Stdout, "", log.LstdFlags),
|
|
36
|
+
error: log.New(os.Stdout, "", log.LstdFlags),
|
|
44
37
|
}
|
|
45
38
|
}
|
|
46
39
|
|
|
47
40
|
func (l *Log) Info(m any) {
|
|
48
|
-
l.info.Println(
|
|
41
|
+
l.info.Println(toJson(m, l.kvs, "INFO"))
|
|
49
42
|
}
|
|
50
43
|
|
|
51
44
|
func (l *Log) Warn(m any) {
|
|
52
|
-
l.warn.Println(
|
|
45
|
+
l.warn.Println(toJson(m, l.kvs, "WARN"))
|
|
53
46
|
}
|
|
54
47
|
|
|
55
48
|
func (l *Log) Error(m any) {
|
|
56
|
-
l.error.Println(
|
|
49
|
+
l.error.Println(toJson(m, l.kvs, "ERROR"))
|
|
57
50
|
}
|
|
58
51
|
|
|
59
52
|
func (l *Log) Fatal(m any) {
|
|
60
|
-
l.error.Fatal(
|
|
53
|
+
l.error.Fatal(toJson(m, l.kvs, "ERROR"))
|
|
61
54
|
}
|
|
62
55
|
|
|
63
56
|
func (l *Log) With(kvs ...any) Logger {
|
|
@@ -76,11 +69,10 @@ func (l *Log) With(kvs ...any) Logger {
|
|
|
76
69
|
}
|
|
77
70
|
|
|
78
71
|
return &Log{
|
|
79
|
-
kvs:
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
error: l.error,
|
|
72
|
+
kvs: newkvs,
|
|
73
|
+
info: l.info,
|
|
74
|
+
warn: l.warn,
|
|
75
|
+
error: l.error,
|
|
84
76
|
}
|
|
85
77
|
}
|
|
86
78
|
|
package/go/log/utils.go
CHANGED
|
@@ -6,12 +6,15 @@ import (
|
|
|
6
6
|
)
|
|
7
7
|
|
|
8
8
|
// toJson converts the message and key-value pairs to a JSON string.
|
|
9
|
-
func toJson(m any, kvs map[string]any) string {
|
|
9
|
+
func toJson(m any, kvs map[string]any, level string) string {
|
|
10
10
|
// copy the key-value pairs into a new map and add the message
|
|
11
11
|
out := make(map[string]any, len(kvs)+1)
|
|
12
12
|
maps.Copy(out, kvs)
|
|
13
13
|
out["msg"] = m
|
|
14
14
|
|
|
15
|
+
// add the log level
|
|
16
|
+
out["level"] = level
|
|
17
|
+
|
|
15
18
|
// marshal the map to a JSON byte array
|
|
16
19
|
data, err := json.Marshal(out)
|
|
17
20
|
if err != nil {
|