aboutsummaryrefslogtreecommitdiff
path: root/go/log
diff options
context:
space:
mode:
Diffstat (limited to 'go/log')
-rw-r--r--go/log/log.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/go/log/log.go b/go/log/log.go
new file mode 100644
index 00000000..ff090425
--- /dev/null
+++ b/go/log/log.go
@@ -0,0 +1,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...)
+}