package log import ( "context" "fmt" "log" "log/slog" ) var GameLogLevel slog.Level = 99 var Logger *slog.Logger var handleGameRecord func(any) // RegisterGameRecordHandler registers a callback for game records. // The registered callback can be used by the game's UI to present game log entries to the user. func RegisterGameRecordHandler(handler func(any)) { handleGameRecord = handler } // Configure controls the logging behavior of the default logger. func Configure(files []string, opts *slog.HandlerOptions) { Logger = slog.New(NewGameLogHandler(files, opts)) slog.SetDefault(Logger) } // Game calls the registered handleGameRecord callback and [Logger.Log] on the default logger. func Game(obj any) { if handleGameRecord != nil { handleGameRecord(obj) } msg := fmt.Sprintf("%s", obj) slog.Log(context.Background(), GameLogLevel, msg) } // Debug calls [Logger.Debug] on the default logger. func Debug(msg string, args ...any) { slog.Debug(msg, args...) } // Info calls [Logger.Info] on the default logger. func Info(msg string, args ...any) { slog.Info(msg, args...) } // Warn calls [Logger.Warn] on the default logger. func Warn(msg string, args ...any) { slog.Warn(msg, args...) } // Error calls [Logger.Error] on the default logger. func Error(msg string, args ...any) { slog.Error(msg, args...) } // Fatal calls [log.Fatal]. func Fatal(args ...any) { log.Fatal(args...) } // Fatalf calls [log.Fatalf]. func Fatalf(msg string, args ...any) { log.Fatalf(msg, args...) } // Panic calls [log.Panic]. func Panic(args ...any) { log.Panic(args...) } // Panicf calls [log.Panicf]. func Panicf(msg string, args ...any) { log.Panicf(msg, args...) }