@rivascva/dt-idl 1.1.91 → 1.1.92
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/utils.go +17 -3
- package/go/utils/types.go +6 -0
- package/package.json +1 -1
package/go/log/utils.go
CHANGED
|
@@ -4,8 +4,8 @@ import (
|
|
|
4
4
|
"context"
|
|
5
5
|
"encoding/json"
|
|
6
6
|
"fmt"
|
|
7
|
-
"maps"
|
|
8
7
|
"runtime"
|
|
8
|
+
"strings"
|
|
9
9
|
"time"
|
|
10
10
|
|
|
11
11
|
"github.com/RivasCVA/dt-idl/go/utils"
|
|
@@ -13,9 +13,20 @@ import (
|
|
|
13
13
|
|
|
14
14
|
// toJson converts the message and key-value pairs to a JSON string.
|
|
15
15
|
func toJson(ctx context.Context, m any, kvs map[string]any, lvl string) string {
|
|
16
|
-
// copy the key-value pairs into a new map
|
|
16
|
+
// copy the key-value pairs into a new map, applying any transformations if necessary
|
|
17
17
|
out := make(map[string]any, len(kvs)+10)
|
|
18
|
-
|
|
18
|
+
for k, v := range kvs {
|
|
19
|
+
if v == nil {
|
|
20
|
+
// ensure nil interfaces are printed as nulls
|
|
21
|
+
out[k] = nil
|
|
22
|
+
} else if e, ok := v.(error); ok {
|
|
23
|
+
// ensure errors are printed as strings
|
|
24
|
+
out[k] = e.Error()
|
|
25
|
+
} else {
|
|
26
|
+
// copy the value as-is
|
|
27
|
+
out[k] = v
|
|
28
|
+
}
|
|
29
|
+
}
|
|
19
30
|
|
|
20
31
|
// add the message
|
|
21
32
|
out["msg"] = m
|
|
@@ -29,6 +40,9 @@ func toJson(ctx context.Context, m any, kvs map[string]any, lvl string) string {
|
|
|
29
40
|
// add the caller
|
|
30
41
|
if pc, file, line, ok := runtime.Caller(2); ok {
|
|
31
42
|
fn := runtime.FuncForPC(pc).Name()
|
|
43
|
+
if i := strings.LastIndex(fn, "."); i != -1 {
|
|
44
|
+
fn = fn[i+1:]
|
|
45
|
+
}
|
|
32
46
|
if fn == "" {
|
|
33
47
|
fn = "unknown"
|
|
34
48
|
}
|