forked from nbd-wtf/go-nostr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog_debug.go
40 lines (34 loc) · 842 Bytes
/
log_debug.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
//go:build debug
package nostr
import (
"encoding/json"
"fmt"
)
func debugLog(str string, args ...any) {
// this is such that we don't modify the actual args that may be used outside of this function
printableArgs := make([]any, len(args))
for i, v := range args {
printableArgs[i] = stringify(v)
}
DebugLogger.Printf(str, printableArgs...)
}
func stringify(anything any) any {
switch v := anything.(type) {
case []any:
// this is such that we don't modify the actual values that may be used outside of this function
printableValues := make([]any, len(v))
for i, subv := range v {
printableValues[i] = stringify(subv)
}
return printableValues
case []json.RawMessage:
j, _ := json.Marshal(v)
return string(j)
case []byte:
return string(v)
case fmt.Stringer:
return v.String()
default:
return v
}
}