diff --git a/src/sdl2/log.rs b/src/sdl2/log.rs index d9b8278bbb..e9fd9e4e45 100644 --- a/src/sdl2/log.rs +++ b/src/sdl2/log.rs @@ -122,72 +122,8 @@ pub fn log(message: &str) { } } -/// Critical log function which takes as priority CRITICAL -#[doc(alias = "SDL_LogCritical")] -pub fn log_critical(message: &str, category: Category) { - unsafe { - log_with_category(message, category, |category, fmt| { - crate::sys::SDL_LogCritical(category, fmt) - }); - } -} - -/// Debug log function which takes as priority DEBUG -#[doc(alias = "SDL_LogDebug")] -pub fn log_debug(message: &str, category: Category) { - unsafe { - log_with_category(message, category, |category, fmt| { - crate::sys::SDL_LogDebug(category, fmt) - }); - } -} - -/// Error log function which takes as priority ERROR -#[doc(alias = "SDL_LogError")] -pub fn log_error(message: &str, category: Category) { - unsafe { - log_with_category(message, category, |category, fmt| { - crate::sys::SDL_LogError(category, fmt) - }); - } -} - -/// Info log function which takes as priority INFO -#[doc(alias = "SDL_LogInfo")] -pub fn log_info(message: &str, category: Category) { - unsafe { - log_with_category(message, category, |category, fmt| { - crate::sys::SDL_LogInfo(category, fmt) - }); - } -} - -/// Verbose log function which takes as priority VERBOSE -#[doc(alias = "SDL_LogVerbose")] -pub fn log_verbose(message: &str, category: Category) { - unsafe { - log_with_category(message, category, |category, fmt| { - crate::sys::SDL_LogVerbose(category, fmt) - }); - } -} - -/// Warn log function which takes as priority WARN -#[doc(alias = "SDL_LogWarn")] -pub fn log_warn(message: &str, category: Category) { - unsafe { - log_with_category(message, category, |category, fmt| { - crate::sys::SDL_LogWarn(category, fmt) - }); - } -} - -/// uses the sdl_log_func to log the message, when category cannot be converted, then Category: Application will be used -fn log_with_category( - message: &str, - category: Category, - sdl_log_func: unsafe fn(category: libc::c_int, fmt: *const libc::c_char), -) { +/// Log function where Category and Priority can be specified +pub fn log_with_category(message: &str, category: Category, priority: Priority) { let message = message.replace('%', "%%"); let message = CString::new(message).unwrap(); let uccategory = Category::into_ll(category).try_into(); @@ -197,6 +133,13 @@ fn log_with_category( }; unsafe { - sdl_log_func(ccategory, message.as_ptr()); + match priority { + Priority::Critical => crate::sys::SDL_LogCritical(ccategory, message.as_ptr()), + Priority::Debug => crate::sys::SDL_LogDebug(ccategory, message.as_ptr()), + Priority::Error => crate::sys::SDL_LogError(ccategory, message.as_ptr()), + Priority::Info => crate::sys::SDL_LogInfo(ccategory, message.as_ptr()), + Priority::Verbose => crate::sys::SDL_LogVerbose(ccategory, message.as_ptr()), + Priority::Warn => crate::sys::SDL_LogWarn(ccategory, message.as_ptr()), + } } }