diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-08-17 15:16:01 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-08-20 15:57:39 +0200 |
| commit | 9463ec4cb063f0bde03d0e1b2a650f5887ad29ff (patch) | |
| tree | 035af855f260b7a9d4e63d0b5ad67000ad6e8ea1 /go/log | |
| parent | 5f97fb7a1606908e99be97d67e5871d55067dac7 (diff) | |
| download | muhqs-game-9463ec4cb063f0bde03d0e1b2a650f5887ad29ff.tar.gz muhqs-game-9463ec4cb063f0bde03d0e1b2a650f5887ad29ff.zip | |
use slog and add game log handler callback
Diffstat (limited to 'go/log')
| -rw-r--r-- | go/log/log.go | 61 |
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...) +} |
