/* +------------------------------------------------------+ ____/ \____ /| - Open source game framework licensed to freely use, | \ / / | copy, modify and sell without restriction | +--\ ^__^ /--+ | | | ~/ \~ | | - created for | | ~~~~~~~~~~~~ | +------------------------------------------------------+ | SPACE ~~~~~ | / | ~~~~~~~ BOX |/ +--------------+ Log messages of specified priority through the SDL logging method, which is overridden in sb::Game to write to stdout, file, or both, depending on the user's configuration settings. */ #pragma once #include #include #include #include /* Include Open GL so GL errors can be logged */ #include "gl.h" namespace sb { class Log { public: /* Equivalent of SDL's SDL_LOG_PRIORITY_* values */ enum Level { VERBOSE = 1, DEBUG, INFO, WARN, ERR, CRITICAL, }; static const int DEFAULT_CATEGORY = SDL_LOG_CATEGORY_CUSTOM; /*! * Send a message to SDL's log function, which currently gets overridden in sb::Game. The default level is Level::INFO. * * Category will default to SDL's custom category. Using the default category will ensure that debug level statements are * handled according to the options in the global configuration. * * @param message text to add to the log * @param level message priority level * @param category a category that matches SDL_LOG_CATEGORY_* */ static void log(const std::string& message, const Level level = INFO, const int category = DEFAULT_CATEGORY); /*! * Send a log statement using a stringstream. * * @see Log::log(const std::string&, const Level, const int) */ static void log(const std::ostringstream& message, const Level level = INFO, const int category = DEFAULT_CATEGORY); /*! * Log all GL errors accumulated since the last time this function was called. * * @param heading optional text to prepend to the error message */ static bool gl_errors(const std::string& heading = ""); /*! * Log a message, adding the results of `SDL_GetError` to the end of the message. This should be used to log a message after an * SDL API function returns an error value because SDL functions are written to set the value of SDL_GetError in that case. The * priority level will be `Level::ERROR` unless a different level is specified. * * @param message text to log before the SDL error is appended * @param level message priority level * @return a string stream containing the full message */ static std::ostringstream sdl_error(const std::string& message = "", const Level level = ERR); }; }