Browse Source

Improve debug logging API

master
Riyyi 3 years ago
parent
commit
230e866e7a
  1. 8
      inferno/src/inferno/application.cpp
  2. 12
      inferno/src/inferno/assert.h
  3. 2
      inferno/src/inferno/io/input.cpp
  4. 54
      inferno/src/inferno/io/log.cpp
  5. 115
      inferno/src/inferno/io/log.h
  6. 8
      inferno/src/inferno/render/context.cpp
  7. 2
      inferno/src/inferno/render/font.cpp
  8. 4
      inferno/src/inferno/render/renderer.cpp
  9. 4
      inferno/src/inferno/render/shader.cpp
  10. 2
      inferno/src/inferno/render/texture.cpp
  11. 2
      inferno/src/inferno/scene/scene.cpp
  12. 6
      inferno/src/inferno/settings.cpp
  13. 2
      inferno/src/inferno/system/camerasystem.cpp
  14. 2
      inferno/src/inferno/system/rendersystem.cpp
  15. 2
      inferno/src/inferno/system/scriptsystem.cpp
  16. 2
      inferno/src/inferno/system/transformsystem.cpp

8
inferno/src/inferno/application.cpp

@ -122,7 +122,7 @@ namespace Inferno {
// borderwidth
// borderedge
// bordercolor
// offse
// offset
while (!m_window->shouldClose()) {
@ -172,7 +172,7 @@ namespace Inferno {
// Suppress unused warning
(void)e;
dbg(Log::Info) << "WindowCloseEvent triggered";
info() << "WindowCloseEvent triggered";
m_window->setShouldClose(true);
@ -184,7 +184,7 @@ namespace Inferno {
// Suppress unused warning
(void)e;
dbgln(Log::Info, "WindowResizeEvent {}x{} triggered", e.getWidth(), e.getHeight());
infoln("WindowResizeEvent {}x{} triggered", e.getWidth(), e.getHeight());
m_window->getContext()->setViewport(0, 0, e.getWidth(), e.getHeight());
@ -196,7 +196,7 @@ namespace Inferno {
// Suppress unused warning
(void)e;
dbgln(Log::Info, "KeyPressEvent {} ({}) triggered",
infoln("KeyPressEvent {} ({}) triggered",
Input::getKeyName(e.getKey()),
e.getKey());

12
inferno/src/inferno/assert.h

@ -41,17 +41,17 @@ namespace Inferno {
#ifdef NF_ENABLE_ASSERTS
template<typename... P>
void __assertion_failed(const char* message, const char* file, unsigned line, const char* function, const P&... parameters)
void __assertion_failed(const char* message, const char* file, unsigned line, const char* function, P&&... parameters)
{
dbg(Log::Danger, false) << "ASSERTION FAILED: " << message;
danger(false) << "ASSERTION FAILED: " << message;
if (sizeof...(P) > 0) {
dbg(Log::Danger, false) << ": ";
dbgln(Log::Danger, false, parameters...);
dbg(Log::Danger, false);
danger(false) << ": ";
dbgln(Log::Danger, false, std::forward<P>(parameters)...);
danger(false);
}
dbg(Log::Danger) << "\n\t" << file << ":" << line << ": " << function;
danger() << "\n\t" << file << ":" << line << ": " << function;
raise(ABORT_SIGNAL);
}

2
inferno/src/inferno/io/input.cpp

@ -20,7 +20,7 @@ namespace Inferno {
m_xPosLast = Application::the().getWindow().getWidth() / 2.0f;
m_yPosLast = Application::the().getWindow().getHeight() / 2.0f;
dbg(Log::Info) << "Input initialized";
info() << "Input initialized";
}
void Input::update()

54
inferno/src/inferno/io/log.cpp

@ -252,66 +252,66 @@ namespace Inferno {
return DebugLogStream(newline);
}
DebugLogStream dbg(Log type)
DebugLogStream info()
{
return DebugLogStream(type);
return DebugLogStream(Log::Info);
}
DebugLogStream dbg(Log type, bool newline)
DebugLogStream warn()
{
return DebugLogStream(type, newline);
return DebugLogStream(Log::Warn);
}
// -----------------------------------------
void dbgln(Log type, bool newline) {
(void)type;
dbg(newline);
DebugLogStream danger()
{
return DebugLogStream(Log::Danger);
}
void dbgln(const char* format)
DebugLogStream success()
{
dbg() << format;
return DebugLogStream(Log::Success);
}
void dbgln(Log type, const char* format)
DebugLogStream comment()
{
dbg(type) << format;
return DebugLogStream(Log::Comment);
}
void dbgln(Log type, bool newline, const char* format)
DebugLogStream info(bool newline)
{
dbg(type, newline) << format;
return DebugLogStream(Log::Info, newline);
}
void dbgln(std::string format)
DebugLogStream warn(bool newline)
{
dbg() << format;
return DebugLogStream(Log::Warn, newline);
}
void dbgln(Log type, std::string format)
DebugLogStream danger(bool newline)
{
dbg(type) << format;
return DebugLogStream(Log::Danger, newline);
}
void dbgln(Log type, bool newline, std::string format)
DebugLogStream success(bool newline)
{
dbg(type, newline) << format;
return DebugLogStream(Log::Success, newline);
}
void dbgln(std::string_view format)
DebugLogStream comment(bool newline)
{
dbg() << format;
return DebugLogStream(Log::Comment, newline);
}
void dbgln(Log type, std::string_view format)
// -----------------------------------------
void dbgln(Log type, bool newline)
{
dbg(type) << format;
(void)type, DebugLogStream(newline);
}
void dbgln(Log type, bool newline, std::string_view format)
void dbgln(Log type, bool newline, const char* format)
{
dbg(type, newline) << format;
DebugLogStream(type, newline) << format;
}
// -----------------------------------------

115
inferno/src/inferno/io/log.h

@ -137,34 +137,67 @@ namespace Inferno {
// -----------------------------------------
DebugLogStream dbg();
DebugLogStream info();
DebugLogStream warn();
DebugLogStream danger();
DebugLogStream success();
DebugLogStream comment();
DebugLogStream dbg(bool newline);
DebugLogStream dbg(Log type);
DebugLogStream dbg(Log type, bool newline);
DebugLogStream info(bool newline);
DebugLogStream warn(bool newline);
DebugLogStream danger(bool newline);
DebugLogStream success(bool newline);
DebugLogStream comment(bool newline);
// -----------------------------------------
void dbgln(Log type, bool newline);
void dbgln(const char* format);
void dbgln(Log type, const char* format);
void dbgln(Log type, bool newline, const char* format);
void dbgln(std::string format);
void dbgln(Log type, std::string format);
void dbgln(Log type, bool newline, std::string format);
void dbgln(std::string_view format);
void dbgln(Log type, std::string_view format);
void dbgln(Log type, bool newline, std::string_view format);
template<typename... P> void dbgln(const char* format, P&&... parameters) { return dbgln(Log::None, true, format, std::forward<P>(parameters)...); }
template<typename... P> void infoln(const char* format, P&&... parameters) { return dbgln(Log::Info, true, format, std::forward<P>(parameters)...); }
template<typename... P> void warnln(const char* format, P&&... parameters) { return dbgln(Log::Warn, true, format, std::forward<P>(parameters)...); }
template<typename... P> void dangerln(const char* format, P&&... parameters) { return dbgln(Log::Danger, true, format, std::forward<P>(parameters)...); }
template<typename... P> void successln(const char* format, P&&... parameters) { return dbgln(Log::Success, true, format, std::forward<P>(parameters)...); }
template<typename... P> void commentln(const char* format, P&&... parameters) { return dbgln(Log::Comment, true, format, std::forward<P>(parameters)...); }
template<typename... P> void dbgln(const std::string& format, P&&... parameters) { return dbgln(Log::None, true, format.c_str(), std::forward<P>(parameters)...); }
template<typename... P> void infoln(const std::string& format, P&&... parameters) { return dbgln(Log::Info, true, format.c_str(), std::forward<P>(parameters)...); }
template<typename... P> void warnln(const std::string& format, P&&... parameters) { return dbgln(Log::Warn, true, format.c_str(), std::forward<P>(parameters)...); }
template<typename... P> void dangerln(const std::string& format, P&&... parameters) { return dbgln(Log::Danger, true, format.c_str(), std::forward<P>(parameters)...); }
template<typename... P> void successln(const std::string& format, P&&... parameters) { return dbgln(Log::Success, true, format.c_str(), std::forward<P>(parameters)...); }
template<typename... P> void commentln(const std::string& format, P&&... parameters) { return dbgln(Log::Comment, true, format.c_str(), std::forward<P>(parameters)...); }
template<typename... P> void dbgln(const std::string_view& format, P&&... parameters) { return dbgln(Log::None, true, format.data(), std::forward<P>(parameters)...); }
template<typename... P> void infoln(const std::string_view& format, P&&... parameters) { return dbgln(Log::Info, true, format.data(), std::forward<P>(parameters)...); }
template<typename... P> void warnln(const std::string_view& format, P&&... parameters) { return dbgln(Log::Warn, true, format.data(), std::forward<P>(parameters)...); }
template<typename... P> void dangerln(const std::string_view& format, P&&... parameters) { return dbgln(Log::Danger, true, format.data(), std::forward<P>(parameters)...); }
template<typename... P> void successln(const std::string_view& format, P&&... parameters) { return dbgln(Log::Success, true, format.data(), std::forward<P>(parameters)...); }
template<typename... P> void commentln(const std::string_view& format, P&&... parameters) { return dbgln(Log::Comment, true, format.data(), std::forward<P>(parameters)...); }
template<typename... P> void dbgln(bool newline, const char* format, P&&... parameters) { return dbgln(Log::None, newline, format, std::forward<P>(parameters)...); }
template<typename... P> void infoln(bool newline, const char* format, P&&... parameters) { return dbgln(Log::Info, newline, format, std::forward<P>(parameters)...); }
template<typename... P> void warnln(bool newline, const char* format, P&&... parameters) { return dbgln(Log::Warn, newline, format, std::forward<P>(parameters)...); }
template<typename... P> void dangerln(bool newline, const char* format, P&&... parameters) { return dbgln(Log::Danger, newline, format, std::forward<P>(parameters)...); }
template<typename... P> void successln(bool newline, const char* format, P&&... parameters) { return dbgln(Log::Success, newline, format, std::forward<P>(parameters)...); }
template<typename... P> void commentln(bool newline, const char* format, P&&... parameters) { return dbgln(Log::Comment, newline, format, std::forward<P>(parameters)...); }
template<typename... P> void dbgln(bool newline, const std::string& format, P&&... parameters) { return dbgln(Log::None, newline, format.c_str(), std::forward<P>(parameters)...); }
template<typename... P> void infoln(bool newline, const std::string& format, P&&... parameters) { return dbgln(Log::Info, newline, format.c_str(), std::forward<P>(parameters)...); }
template<typename... P> void warnln(bool newline, const std::string& format, P&&... parameters) { return dbgln(Log::Warn, newline, format.c_str(), std::forward<P>(parameters)...); }
template<typename... P> void dangerln(bool newline, const std::string& format, P&&... parameters) { return dbgln(Log::Danger, newline, format.c_str(), std::forward<P>(parameters)...); }
template<typename... P> void successln(bool newline, const std::string& format, P&&... parameters) { return dbgln(Log::Success, newline, format.c_str(), std::forward<P>(parameters)...); }
template<typename... P> void commentln(bool newline, const std::string& format, P&&... parameters) { return dbgln(Log::Comment, newline, format.c_str(), std::forward<P>(parameters)...); }
template<typename... P> void dbgln(bool newline, const std::string_view& format, P&&... parameters) { return dbgln(Log::None, newline, format.data(), std::forward<P>(parameters)...); }
template<typename... P> void infoln(bool newline, const std::string_view& format, P&&... parameters) { return dbgln(Log::Info, newline, format.data(), std::forward<P>(parameters)...); }
template<typename... P> void warnln(bool newline, const std::string_view& format, P&&... parameters) { return dbgln(Log::Warn, newline, format.data(), std::forward<P>(parameters)...); }
template<typename... P> void dangerln(bool newline, const std::string_view& format, P&&... parameters) { return dbgln(Log::Danger, newline, format.data(), std::forward<P>(parameters)...); }
template<typename... P> void successln(bool newline, const std::string_view& format, P&&... parameters) { return dbgln(Log::Success, newline, format.data(), std::forward<P>(parameters)...); }
template<typename... P> void commentln(bool newline, const std::string_view& format, P&&... parameters) { return dbgln(Log::Comment, newline, format.data(), std::forward<P>(parameters)...); }
template<typename T, typename... P>
void dbgln(const char* format, T value, P&&... parameters)
{
dbgln(Log::None, format, value, std::forward<P>(parameters)...);
}
// -----------------------------------------
template<typename T, typename... P>
void dbgln(Log type, const char* format, T value, P&&... parameters)
{
dbgln(type, true, format, value, std::forward<P>(parameters)...);
}
void dbgln(Log type, bool newline);
void dbgln(Log type, bool newline, const char* format);
// https://en.cppreference.com/w/cpp/language/parameter_pack#Example
template<typename T, typename... P>
@ -176,7 +209,7 @@ namespace Inferno {
while(format[i] != '\0') {
if (format[i] == '{' && format[i + 1] == '}') {
dbg(type, false) << view.substr(0, i) << value;
DebugLogStream(type, false) << view.substr(0, i) << value;
dbgln(type, newline, format + i + 2, parameters...);
return;
}
@ -185,42 +218,6 @@ namespace Inferno {
}
}
template<typename T, typename... P>
void dbgln(std::string format, T value, P&&... parameters)
{
dbgln(format.c_str(), value, std::forward<P>(parameters)...);
}
template<typename T, typename... P>
void dbgln(Log type, std::string format, T value, P&&... parameters)
{
dbgln(type, format.c_str(), value, std::forward<P>(parameters)...);
}
template<typename T, typename... P>
void dbgln(Log type, bool newline, std::string format, T value, P&&... parameters)
{
dbgln(type, newline, format.c_str(), value, std::forward<P>(parameters)...);
}
template<typename T, typename... P>
void dbgln(std::string_view format, T value, P&&... parameters)
{
dbgln(format.data(), value, std::forward<P>(parameters)...);
}
template<typename T, typename... P>
void dbgln(Log type, std::string_view format, T value, P&&... parameters)
{
dbgln(type, format.data(), value, std::forward<P>(parameters)...);
}
template<typename T, typename... P>
void dbgln(Log type, bool newline, std::string_view format, T value, P&&... parameters)
{
dbgln(type, newline, format.data(), value, std::forward<P>(parameters)...);
}
// -----------------------------------------
StringLogStream str(std::string* fill);

8
inferno/src/inferno/render/context.cpp

@ -24,10 +24,10 @@ namespace Inferno {
ASSERT(glad, "Failed to initialize glad!");
// Log OpenGL properties
dbg(Log::Comment) << "OpenGL Info:";
dbg(Log::Comment) << " Vendor: " << glGetString(GL_VENDOR);
dbg(Log::Comment) << " Renderer: " << glGetString(GL_RENDERER);
dbg(Log::Comment) << " Version: " << glGetString(GL_VERSION);
comment() << "OpenGL Info:";
comment() << " Vendor: " << glGetString(GL_VENDOR);
comment() << " Renderer: " << glGetString(GL_RENDERER);
comment() << " Version: " << glGetString(GL_VERSION);
#ifdef NF_ENABLE_ASSERTS
int versionMajor;

2
inferno/src/inferno/render/font.cpp

@ -95,7 +95,7 @@ namespace Inferno {
ASSERT(!s_instance, "FontManager already exists!");
s_instance = this;
dbg(Log::Info) << "FontManager initialized";
info() << "FontManager initialized";
}
void FontManager::destroy()

4
inferno/src/inferno/render/renderer.cpp

@ -174,7 +174,7 @@ namespace Inferno {
m_vertexArray->setIndexBuffer(indexBuffer);
delete[] indices;
dbg(Log::Info) << "Renderer2D initialized";
info() << "Renderer2D initialized";
}
void Renderer2D::destroy()
@ -331,7 +331,7 @@ namespace Inferno {
m_vertexArray->setIndexBuffer(indexBuffer);
delete[] indices;
dbg(Log::Info) << "RendererCharacter initialized";
info() << "RendererCharacter initialized";
}
void RendererCharacter::destroy()

4
inferno/src/inferno/render/shader.cpp

@ -181,7 +181,7 @@ namespace Inferno {
? glGetShaderInfoLog(check, maxLength, nullptr, &infoLog[0])
: glGetProgramInfoLog(check, maxLength, nullptr, &infoLog[0]);
dbg(Log::Warn) << "Shader " << infoLog.data();
warn() << "Shader " << infoLog.data();
}
ASSERT(success == GL_TRUE, "Shader program creation failed!");
@ -198,7 +198,7 @@ namespace Inferno {
ASSERT(!s_instance, "ShaderManager already exists!");
s_instance = this;
dbg(Log::Info) << "ShaderManager initialized";
info() << "ShaderManager initialized";
}
void ShaderManager::destroy()

2
inferno/src/inferno/render/texture.cpp

@ -108,7 +108,7 @@ namespace Inferno {
ASSERT(!s_instance, "TextureManager already exists!");
s_instance = this;
dbg(Log::Info) << "TextureManager initialized";
info() << "TextureManager initialized";
}
void TextureManager::destroy()

2
inferno/src/inferno/scene/scene.cpp

@ -67,7 +67,7 @@ namespace Inferno {
quad3Transform.translate.x = 2.2f;
addComponent<SpriteComponent>(quad3, glm::vec4 { 1.0f, 1.0f, 1.0f, 1.0f }, m_texture2);
dbg(Log::Info) << "Scene initialized";
info() << "Scene initialized";
}
void Scene::update(float deltaTime)

6
inferno/src/inferno/settings.cpp

@ -13,7 +13,7 @@ namespace Inferno {
{
Settings::update();
dbg(Log::Info) << "Settings initialized";
info() << "Settings initialized";
}
void Settings::update()
@ -29,7 +29,7 @@ namespace Inferno {
m_properties.window.vsync = json["window"]["vsync"].get<bool>();
}
catch (...) {
dbg(Log::Warn) << "Settings syntax error: using default values";
warn() << "Settings syntax error: using default values";
}
}
@ -54,7 +54,7 @@ namespace Inferno {
json["window"]["vsync"] = m_properties.window.vsync;
File::ioWrite(json, m_path);
dbg(Log::Info) << "Settings saved";
info() << "Settings saved";
return true;
}

2
inferno/src/inferno/system/camerasystem.cpp

@ -17,7 +17,7 @@ namespace Inferno {
ASSERT(!s_instance, "CameraSystem already exists!");
s_instance = this;
dbg(Log::Info) << "CameraSystem initialized";
info() << "CameraSystem initialized";
}
void CameraSystem::update()

2
inferno/src/inferno/system/rendersystem.cpp

@ -16,7 +16,7 @@ namespace Inferno {
ASSERT(!s_instance, "RenderSystem already exists!");
s_instance = this;
dbg(Log::Info) << "RenderSystem initialized";
info() << "RenderSystem initialized";
}
void RenderSystem::render()

2
inferno/src/inferno/system/scriptsystem.cpp

@ -19,7 +19,7 @@ namespace Inferno {
ASSERT(!s_instance, "ScriptSystem already exists!");
s_instance = this;
dbg(Log::Info) << "ScriptSystem initialized";
info() << "ScriptSystem initialized";
}
void ScriptSystem::destroy()

2
inferno/src/inferno/system/transformsystem.cpp

@ -14,7 +14,7 @@ namespace Inferno {
ASSERT(!s_instance, "TransformSystem already exists!");
s_instance = this;
dbg(Log::Info) << "TransformSystem initialized";
info() << "TransformSystem initialized";
}
void TransformSystem::update()

Loading…
Cancel
Save