94 lines
3.0 KiB
C++
94 lines
3.0 KiB
C++
/* +------------------------------------------------------+
|
|
____/ \____ /| - Open source game framework licensed to freely use, |
|
|
\ / / | copy, modify and sell without restriction |
|
|
+--\ ^__^ /--+ | |
|
|
| ~/ \~ | | - created for <https://foam.shampoo.ooo> |
|
|
| ~~~~~~~~~~~~ | +------------------------------------------------------+
|
|
| SPACE ~~~~~ | /
|
|
| ~~~~~~~ BOX |/
|
|
+-------------*/
|
|
|
|
/*! @file
|
|
|
|
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 Open GL */
|
|
#if defined(__EMSCRIPTEN__)
|
|
#include <GL/glew.h>
|
|
#elif defined(__ANDROID__) && defined(ANDROID)
|
|
#include <GLES3/gl3.h>
|
|
#include <GLES3/gl3ext.h>
|
|
#else
|
|
#include "glew/glew.h"
|
|
#endif
|
|
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include <functional>
|
|
#include <SDL.h>
|
|
|
|
namespace sb
|
|
{
|
|
|
|
class Log
|
|
{
|
|
|
|
public:
|
|
|
|
/* Equivalent of SDL's SDL_LOG_PRIORITY_* values */
|
|
enum Level
|
|
{
|
|
VERBOSE = 1,
|
|
DEBUG,
|
|
INFO,
|
|
WARN,
|
|
ERROR,
|
|
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. Should be used to add more information to
|
|
* an error statement when the error happened in SDL. The priority level will always be `Level::ERROR`.
|
|
*
|
|
* @param message text to log before the SDL error is appended
|
|
* @return a string stream containing the full message
|
|
*/
|
|
static std::ostringstream sdl_error(const std::string& message = "");
|
|
|
|
};
|
|
|
|
}
|