Browse Source

Improve debug logging API

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

12
inferno/src/inferno/assert.h

@ -41,17 +41,17 @@ namespace Inferno {
#ifdef NF_ENABLE_ASSERTS #ifdef NF_ENABLE_ASSERTS
template<typename... P> 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) { if (sizeof...(P) > 0) {
dbg(Log::Danger, false) << ": "; danger(false) << ": ";
dbgln(Log::Danger, false, parameters...); dbgln(Log::Danger, false, std::forward<P>(parameters)...);
dbg(Log::Danger, false); danger(false);
} }
dbg(Log::Danger) << "\n\t" << file << ":" << line << ": " << function; danger() << "\n\t" << file << ":" << line << ": " << function;
raise(ABORT_SIGNAL); 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_xPosLast = Application::the().getWindow().getWidth() / 2.0f;
m_yPosLast = Application::the().getWindow().getHeight() / 2.0f; m_yPosLast = Application::the().getWindow().getHeight() / 2.0f;
dbg(Log::Info) << "Input initialized"; info() << "Input initialized";
} }
void Input::update() void Input::update()

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -67,7 +67,7 @@ namespace Inferno {
quad3Transform.translate.x = 2.2f; quad3Transform.translate.x = 2.2f;
addComponent<SpriteComponent>(quad3, glm::vec4 { 1.0f, 1.0f, 1.0f, 1.0f }, m_texture2); 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) void Scene::update(float deltaTime)

6
inferno/src/inferno/settings.cpp

@ -13,7 +13,7 @@ namespace Inferno {
{ {
Settings::update(); Settings::update();
dbg(Log::Info) << "Settings initialized"; info() << "Settings initialized";
} }
void Settings::update() void Settings::update()
@ -29,7 +29,7 @@ namespace Inferno {
m_properties.window.vsync = json["window"]["vsync"].get<bool>(); m_properties.window.vsync = json["window"]["vsync"].get<bool>();
} }
catch (...) { 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; json["window"]["vsync"] = m_properties.window.vsync;
File::ioWrite(json, m_path); File::ioWrite(json, m_path);
dbg(Log::Info) << "Settings saved"; info() << "Settings saved";
return true; return true;
} }

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

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

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

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

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

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

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

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

Loading…
Cancel
Save