-
Notifications
You must be signed in to change notification settings - Fork 8
/
log.go
31 lines (27 loc) · 661 Bytes
/
log.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
package htmltable
import (
"context"
"fmt"
"log"
"strings"
)
// Logger is a very simplistic structured logger, than should
// be overriden by integrations.
var Logger func(_ context.Context, msg string, fields ...any)
func init() {
Logger = defaultLogger
}
var defaultLogger = func(_ context.Context, msg string, fields ...any) {
var sb strings.Builder
sb.WriteString(msg)
if len(fields)%2 != 0 {
panic(fmt.Errorf("number of logged fields is not even"))
}
for i := 0; i < len(fields); i += 2 {
sb.WriteRune(' ')
sb.WriteString(fmt.Sprint(fields[i]))
sb.WriteRune('=')
sb.WriteString(fmt.Sprint(fields[i+1]))
}
log.Print(sb.String())
}