-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogger.go
45 lines (36 loc) · 851 Bytes
/
logger.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
//go:build js && wasm
package client
import (
"os" //nolint:gci
"syscall/js"
)
// Logger binds to the looking glass logger in the browser.
type Logger struct {
name string
}
// NewLogger returns a new logger.
func NewLogger() *Logger {
name := os.Args[0]
return &Logger{
name: name,
}
}
// Debug writes a debug log message.
func (l *Logger) Debug(msg string, kvs ...string) {
js.Global().Call("log.debug", msg, toSliceAny(kvs))
}
// Info writes a info log message.
func (l *Logger) Info(msg string, kvs ...string) {
js.Global().Call("log.info", msg, toSliceAny(kvs))
}
// Error writes a error log message.
func (l *Logger) Error(msg string, kvs ...string) {
js.Global().Call("log.error", msg, toSliceAny(kvs))
}
func toSliceAny[T any](a []T) []any {
arr := make([]any, len(a))
for i, s := range a {
arr[i] = s
}
return arr
}