aboutsummaryrefslogtreecommitdiff
path: root/go/log/log.go
blob: ff0904250bfcaa1b54243c2b36e6c8b6a4dd889e (plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package log

import (
	"context"
	"fmt"
	"log"
	"log/slog"
	"os"
)

const GameLogLevel = 99

var handleGameRecord func(any)

func init() {
	// TODO: allow to specify the value and the file
	l := slog.New(slog.NewTextHandler(
		os.Stdout,
		&slog.HandlerOptions{AddSource: true}))
	slog.SetDefault(l)
}

func Game(obj any) {
	if handleGameRecord != nil {
		handleGameRecord(obj)
	}
	msg := fmt.Sprintf("%s", obj)
	slog.Log(context.Background(), GameLogLevel, msg)
}

func Debug(msg string, args ...any) {
	slog.Debug(msg, args...)
}

func Info(msg string, args ...any) {
	slog.Info(msg, args...)
}

func Warn(msg string, args ...any) {
	slog.Warn(msg, args...)
}

func Error(msg string, args ...any) {
	slog.Error(msg, args...)
}

func Fatal(args ...any) {
	log.Fatal(args...)
}

func Fatalf(msg string, args ...any) {
	log.Fatalf(msg, args...)
}

func Panic(args ...any) {
	log.Panic(args...)
}

func Panicf(msg string, args ...any) {
	log.Panicf(msg, args...)
}