diff options
| author | Levent Kaya <levent@dev> | 2025-11-06 11:49:26 +0300 |
|---|---|---|
| committer | Levent Kaya <levent@dev> | 2025-11-06 11:49:26 +0300 |
| commit | c804988f70ad580b45ab5adda64022f462dc6599 (patch) | |
| tree | 2568944c8a7d0950a5bff73bd2905109e123a4a3 /src | |
| parent | d2bb3c90b4e8dffaabb2315df13a2dbd362bb1b7 (diff) | |
[feature] global logger implemented
Diffstat (limited to 'src')
| -rw-r--r-- | src/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/main.cpp | 148 | ||||
| -rw-r--r-- | src/util/logger.cpp | 29 |
3 files changed, 106 insertions, 72 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9875cd7..9bad7f7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,6 +4,7 @@ cmake_minimum_required(VERSION 3.15) # local guard if included standalone # Collect core sources (placeholder + real sources later) set(BOLTDBG_CORE_SOURCES dummy.cpp # placeholder; replace/add real core sources here + util/logger.cpp # src/core/debugger.cpp # src/core/process.cpp ) diff --git a/src/main.cpp b/src/main.cpp index 0a23004..b9a327f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,14 +1,12 @@ // src/main.cpp #include <iostream> -// spdlog -#include <spdlog/spdlog.h> - // Prevent GLFW from including OpenGL headers (so glad can provide them) #define GLFW_INCLUDE_NONE #include <GLFW/glfw3.h> -// GL loader (glad) - include after GLFW_INCLUDE_NONE so glad can provide GL headers +// GL loader (glad) - include after GLFW_INCLUDE_NONE so glad can provide GL +// headers #if __has_include("glad/glad.h") #include <glad/glad.h> #define HAVE_GLAD 1 @@ -16,103 +14,109 @@ #define HAVE_GLAD 0 #endif -// Now include ImGui and its backends (they expect glfw + GL loader to be present) +// Now include ImGui and its backends (they expect glfw + GL loader to be +// present) #include "imgui.h" #include "backends/imgui_impl_glfw.h" #include "backends/imgui_impl_opengl3.h" -int main(int argc, char** argv) { - // init logger - try { - spdlog::set_level(spdlog::level::info); - spdlog::info("BoltDBG demo starting (spdlog initialized)."); - } catch (const std::exception &e) { - std::cerr << "spdlog init failed: " << e.what() << std::endl; - } +#include <boltdbg/util/logger.h> + +int main(int argc, char **argv) +{ - if (!glfwInit()) { - spdlog::error("Failed to initialize GLFW"); - return 1; + if(!glfwInit()) + { + LOG_ERROR("Failed to initialize GLFW"); + return 1; } - // GL settings (3.3 core as example) - const char* glsl_version = "#version 330"; - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); + // GL settings (3.3 core as example) + const char *glsl_version = "#version 330"; + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); #if __APPLE__ - glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); - glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); #endif - GLFWwindow* window = glfwCreateWindow(1280, 720, "BoltDBG - ImGui + spdlog demo", NULL, NULL); - if (!window) { - spdlog::error("Failed to create GLFW window"); - glfwTerminate(); - return 1; + GLFWwindow *window + = glfwCreateWindow(1280, 720, "BoltDBG", NULL, NULL); + if(!window) + { + LOG_ERROR("Failed to create GLFW window"); + glfwTerminate(); + return 1; } - glfwMakeContextCurrent(window); - glfwSwapInterval(1); + glfwMakeContextCurrent(window); + glfwSwapInterval(1); #if HAVE_GLAD - if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { - spdlog::error("Failed to initialize GLAD"); - return 1; + if(!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) + { + LOG_ERROR("Failed to initialize GLAD"); + return 1; } #else - spdlog::warn("GLAD not detected at compile-time. If you experience GL symbol errors, add glad."); + LOG_WARN("GLAD not detected at compile-time. If you experience GL " + "symbol errors, add glad."); #endif - // ImGui init - IMGUI_CHECKVERSION(); - ImGui::CreateContext(); - ImGuiIO &io = ImGui::GetIO(); (void)io; - ImGui::StyleColorsDark(); + // ImGui init + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGuiIO &io = ImGui::GetIO(); + (void)io; + ImGui::StyleColorsDark(); - ImGui_ImplGlfw_InitForOpenGL(window, true); - ImGui_ImplOpenGL3_Init(glsl_version); + ImGui_ImplGlfw_InitForOpenGL(window, true); + ImGui_ImplOpenGL3_Init(glsl_version); - spdlog::info("Entering main loop."); + LOG_INFO("Entering main loop."); - bool show_demo = false; - int click_count = 0; + bool show_demo = false; + int click_count = 0; - while (!glfwWindowShouldClose(window)) { - glfwPollEvents(); + while(!glfwWindowShouldClose(window)) + { + glfwPollEvents(); - ImGui_ImplOpenGL3_NewFrame(); - ImGui_ImplGlfw_NewFrame(); - ImGui::NewFrame(); + ImGui_ImplOpenGL3_NewFrame(); + ImGui_ImplGlfw_NewFrame(); + ImGui::NewFrame(); - ImGui::Begin("BoltDBG - Demo"); - ImGui::Text("Hello from BoltDBG demo!"); - if (ImGui::Button("Log info with spdlog")) { - click_count++; - spdlog::info("Button clicked {} times", click_count); + ImGui::Begin("BoltDBG - Demo"); + ImGui::Text("Hello from BoltDBG demo!"); + if(ImGui::Button("Log info with spdlog")) + { + click_count++; + LOG_INFO("Button clicked {} times", click_count); } - ImGui::Text("Click count: %d", click_count); - ImGui::End(); + ImGui::Text("Click count: %d", click_count); + ImGui::End(); - if (show_demo) ImGui::ShowDemoWindow(&show_demo); + if(show_demo) + ImGui::ShowDemoWindow(&show_demo); - ImGui::Render(); - int display_w, display_h; - glfwGetFramebufferSize(window, &display_w, &display_h); - glViewport(0, 0, display_w, display_h); - glClearColor(0.1f, 0.12f, 0.14f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT); - ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); + ImGui::Render(); + int display_w, display_h; + glfwGetFramebufferSize(window, &display_w, &display_h); + glViewport(0, 0, display_w, display_h); + glClearColor(0.1f, 0.12f, 0.14f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); - glfwSwapBuffers(window); + glfwSwapBuffers(window); } - // cleanup - ImGui_ImplOpenGL3_Shutdown(); - ImGui_ImplGlfw_Shutdown(); - ImGui::DestroyContext(); + // cleanup + ImGui_ImplOpenGL3_Shutdown(); + ImGui_ImplGlfw_Shutdown(); + ImGui::DestroyContext(); - glfwDestroyWindow(window); - glfwTerminate(); + glfwDestroyWindow(window); + glfwTerminate(); - spdlog::info("BoltDBG demo exiting."); - return 0; + LOG_INFO("BoltDBG demo exiting."); + return 0; } diff --git a/src/util/logger.cpp b/src/util/logger.cpp new file mode 100644 index 0000000..1586743 --- /dev/null +++ b/src/util/logger.cpp @@ -0,0 +1,29 @@ +#include <boltdbg/util/logger.h> +#include <spdlog/sinks/basic_file_sink.h> +#include <spdlog/sinks/stdout_color_sinks.h> +#include <spdlog/sinks/ostream_sink.h> +#include <spdlog/sinks/msvc_sink.h> +#include <vector> + +namespace Log { + +std::shared_ptr<spdlog::logger>& get() { + static std::shared_ptr<spdlog::logger> logger = [] { + + std::vector<spdlog::sink_ptr> sinks; + sinks.push_back(std::make_shared<spdlog::sinks::stdout_color_sink_mt>()); + sinks.push_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>("app.log", true)); + + auto logger = std::make_shared<spdlog::logger>("global", sinks.begin(), sinks.end()); + logger->set_level(spdlog::level::trace); + logger->set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%^%l%$] [thread %t] [%s:%#] %v"); + + spdlog::register_logger(logger); + spdlog::set_default_logger(logger); + + return logger; + }(); + return logger; +} + +} // namespace log |
