namespace Brutal.SdlApi; public static unsafe partial class Sdl { /// /// Ergonomic wrappers over SDL's logging family (SDL_Log, SDL_LogInfo, …, /// SDL_LogMessage). /// /// /// SDL's logging functions are variadic in C and so were skipped by the raw generator; these /// fixed-arity wrappers expose them safely. Each routes through /// (SDL_LogMessage), passing the caller's text as the format string with no variadic /// arguments. Any % in the message is escaped to %% so the text is emitted literally /// and SDL's printf parser never reads a non-existent argument. /// /// This nested class reclaims the Sdl.Log name for the SDL logging surface. The per-call /// trace category the generated P/Invoke wrappers use is the separate internal /// field, so there is no collision. /// /// public static class Log { /// /// Logs with the given category and priority through SDL's logging /// system (SDL_LogMessage). /// /// The SDL log category. /// The message priority. /// The message text (treated literally; % is not a format specifier). public static void Message(SdlLogCategory category, SdlLogPriority priority, string message) { ArgumentNullException.ThrowIfNull(message); PInvoke.LogMessage((int)category, priority, Escape(message)); } /// /// Logs at under the /// category (the SDL_Log default). /// /// The message text. public static void Message(string message) => Message(SdlLogCategory.Application, SdlLogPriority.Info, message); /// Logs a message at (SDL_LogTrace). /// The SDL log category. /// The message text. public static void Trace(SdlLogCategory category, string message) => Message(category, SdlLogPriority.Trace, message); /// Logs a message at (SDL_LogVerbose). /// The SDL log category. /// The message text. public static void Verbose(SdlLogCategory category, string message) => Message(category, SdlLogPriority.Verbose, message); /// Logs a message at (SDL_LogDebug). /// The SDL log category. /// The message text. public static void Debug(SdlLogCategory category, string message) => Message(category, SdlLogPriority.Debug, message); /// Logs a message at (SDL_LogInfo). /// The SDL log category. /// The message text. public static void Info(SdlLogCategory category, string message) => Message(category, SdlLogPriority.Info, message); /// Logs a message at (SDL_LogWarn). /// The SDL log category. /// The message text. public static void Warn(SdlLogCategory category, string message) => Message(category, SdlLogPriority.Warn, message); /// Logs a message at (SDL_LogError). /// The SDL log category. /// The message text. public static void Error(SdlLogCategory category, string message) => Message(category, SdlLogPriority.Error, message); /// Logs a message at (SDL_LogCritical). /// The SDL log category. /// The message text. public static void Critical(SdlLogCategory category, string message) => Message(category, SdlLogPriority.Critical, message); // Escapes printf conversion specifiers so the caller's text is logged verbatim. private static string Escape(string message) => message.Contains('%') ? message.Replace("%", "%%") : message; } }