Skip to content

Commit

Permalink
Utilities : A little log utility
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomrno committed May 7, 2024
1 parent 4c6b846 commit 00f932a
Show file tree
Hide file tree
Showing 7 changed files with 212 additions and 9 deletions.
Binary file modified build/bin/vortex
Binary file not shown.
4 changes: 4 additions & 0 deletions main/src/vortex/logger/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ VORTEX_API void VortexMaker::LogInfo(const std::string& scope, const std::string

if(ctx.logger_registering){
std::shared_ptr<VxSystemLog> log = std::make_shared<VxSystemLog>(spdlog::level::level_enum::info, scope, message);
log->m_timestamp = VortexMaker::getCurrentTimeStamp();
ctx.registered_logs.push_back(log);
}
}
Expand All @@ -36,6 +37,7 @@ VORTEX_API void VortexMaker::LogWarn(const std::string& scope, const std::string

if(ctx.logger_registering){
std::shared_ptr<VxSystemLog> log = std::make_shared<VxSystemLog>(spdlog::level::level_enum::warn, scope, message);
log->m_timestamp = VortexMaker::getCurrentTimeStamp();
ctx.registered_logs.push_back(log);
}
}
Expand All @@ -56,6 +58,7 @@ VORTEX_API void VortexMaker::LogError(const std::string& scope, const std::strin

if(ctx.logger_registering){
std::shared_ptr<VxSystemLog> log = std::make_shared<VxSystemLog>(spdlog::level::level_enum::err, scope, message);
log->m_timestamp = VortexMaker::getCurrentTimeStamp();
ctx.registered_logs.push_back(log);
}
}
Expand All @@ -76,6 +79,7 @@ VORTEX_API void VortexMaker::LogFatal(const std::string& scope, const std::strin

if(ctx.logger_registering){
std::shared_ptr<VxSystemLog> log = std::make_shared<VxSystemLog>(spdlog::level::level_enum::critical, scope, message);
log->m_timestamp = VortexMaker::getCurrentTimeStamp();
ctx.registered_logs.push_back(log);
}
}
Expand Down
12 changes: 3 additions & 9 deletions tools/editor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

file(GLOB_RECURSE EDITOR_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/app/*.cpp")



add_library(editor
Expand All @@ -21,15 +23,7 @@ add_library(editor
${CMAKE_CURRENT_SOURCE_DIR}/../../lib/uikit/platform/GUI/editor/Image.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../lib/uikit/src/core/Log.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../lib/uikit/assets/icons.cpp

${CMAKE_CURRENT_SOURCE_DIR}/app/core/ContentBrowser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/app/core/ProjectViewer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/app/core/TemplateManager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/app/core/ModuleManager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/app/core/ProjectSettings.cpp
${CMAKE_CURRENT_SOURCE_DIR}/app/src/editor.cpp

${CMAKE_CURRENT_SOURCE_DIR}/app/instances/Utils/ModuleDetails/ModuleDetails.cpp
${EDITOR_SOURCES}
)


Expand Down
157 changes: 157 additions & 0 deletions tools/editor/app/core/LogUtility.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#include "LogUtility.hpp"

#include <iostream>

static bool ErrorFilter = true;
static bool WarnFilter = true;
static bool FatalFilter = true;
static bool InfoFilter = true;

LogUtility::LogUtility(VxContext *_ctx, InstanceFactory *_factory)
{
this->ctx = _ctx;
this->factory = _factory;

{
uint32_t w, h;
void *data = UIKit::Image::Decode(icons::i_list, icons::i_list_size, w, h);
m_ListIcon = std::make_shared<UIKit::Image>(w, h, UIKit::ImageFormat::RGBA, data);
free(data);
}
{
uint32_t w, h;
void *data = UIKit::Image::Decode(icons::i_refresh, icons::i_refresh_size, w, h);
m_RefreshIcon = std::make_shared<UIKit::Image>(w, h, UIKit::ImageFormat::RGBA, data);
free(data);
}
{
uint32_t w, h;
void *data = UIKit::Image::Decode(icons::i_add, icons::i_add_size, w, h);
m_AddIcon = std::make_shared<UIKit::Image>(w, h, UIKit::ImageFormat::RGBA, data);
free(data);
}
}

void LogUtility::OnImGuiRender()
{
static ImTextureID listIcon = this->m_ListIcon->GetImGuiTextureID(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);

if (ImGui::Begin("Project Viewer", &listIcon, &this->opened, ImGuiWindowFlags_MenuBar))
{
this->menubar();
}

float oldsize = ImGui::GetFont()->Scale;
ImGui::GetFont()->Scale *= 1.3;
ImGui::PushFont(ImGui::GetFont());

ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 0.5f), "Project contents of : ");
ImGui::SameLine();
// ImGui::Text(this->ctx->name.c_str());

ImGui::GetFont()->Scale = oldsize;
ImGui::PopFont();

ImGui::Separator();

static ImGuiTableFlags flags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_RowBg | ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable;
const float TEXT_BASE_WIDTH = ImGui::CalcTextSize("A").x;

if (ImGui::BeginTable("3ways", 4, flags))
{
// The first column will use the default _WidthStretch when ScrollX is Off and _WidthFixed when ScrollX is On
ImGui::TableSetupColumn("Level", ImGuiTableColumnFlags_NoHide);
ImGui::TableSetupColumn("Timestamp", ImGuiTableColumnFlags_WidthFixed, TEXT_BASE_WIDTH * 18.0f);
ImGui::TableSetupColumn("Origin", ImGuiTableColumnFlags_WidthFixed, TEXT_BASE_WIDTH * 12.0f);
ImGui::TableSetupColumn("Log", ImGuiTableColumnFlags_WidthFixed, TEXT_BASE_WIDTH * 18.0f);
ImGui::TableHeadersRow();

for (auto log : this->ctx->registered_logs)
{
if (log->m_level == spdlog::level::critical && !FatalFilter)
continue;
if (log->m_level == spdlog::level::err && !ErrorFilter)
continue;
if (log->m_level == spdlog::level::warn && !WarnFilter)
continue;
if (log->m_level == spdlog::level::info && !InfoFilter)
continue;

ImGui::TableNextRow();
for (int i = 0; i <= 3; i++)
{
ImGui::TableSetColumnIndex(i);
if (i == 0)
{
if (log->m_level == spdlog::level::critical)
{
ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), "Fatal");
}
else if (log->m_level == spdlog::level::err)
{
ImGui::TextColored(ImVec4(0.8f, 0.2f, 0.2f, 1.0f), "Error");
}
else if (log->m_level == spdlog::level::warn)
{
ImGui::TextColored(ImVec4(0.8f, 0.8f, 0.0f, 1.0f), "Warning");
}
else if (log->m_level == spdlog::level::info)
{
ImGui::TextColored(ImVec4(0.0f, 1.0f, 0.0f, 1.0f), "Information");
}
}
else if (i == 1)
{
ImGui::Text(log->m_timestamp.c_str());
}
else if (i == 2)
{
ImGui::Text(log->m_filter.c_str());
}
else if (i == 3)
{
ImGui::Text(log->m_message.c_str());
}
}
}
ImGui::EndTable();
}

ImGui::End();
}

void LogUtility::menubar()
{
static ImTextureID refreshIcon = this->m_RefreshIcon->GetImGuiTextureID(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
static ImTextureID addIcon = this->m_AddIcon->GetImGuiTextureID(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);

if (ImGui::BeginMenuBar())
{

if (ImGui::ImageButtonWithText(refreshIcon, "Refresh", ImVec2(this->m_RefreshIcon->GetWidth(), this->m_RefreshIcon->GetHeight())))
{
}
if (ImGui::ImageButtonWithText(addIcon, "Add", ImVec2(this->m_AddIcon->GetWidth(), this->m_AddIcon->GetHeight())))
{
ImGui::OpenPopup("CreationMenu");
}
ImGui::Separator();
if (ImGui::BeginMenu("Filters"))
{
ImGui::Checkbox("Show informations", &InfoFilter);
ImGui::Checkbox("Show fatal errors", &FatalFilter);
ImGui::Checkbox("Show errors", &ErrorFilter);
ImGui::Checkbox("Show warnings", &WarnFilter);
if (ImGui::MenuItem("Build/Rebuild single parts"))
{
// Behavior
}
if (ImGui::MenuItem("Global build"))
{
// Behavior
}
ImGui::EndMenu();
}
ImGui::EndMenuBar();
}
}
30 changes: 30 additions & 0 deletions tools/editor/app/core/LogUtility.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

// #include "../instances/Components/Host/HostInstance.h"
// #include "../instances/Components/Toolchain/ToolchainInstance.h"

#ifndef LOGUTILITY_H
#define LOGUTILITY_H

#include "../include/instanceFactory.h"

class LogUtility
{
public:
LogUtility(VxContext *_ctx, InstanceFactory *_factory);

void OnImGuiRender();
void menubar();

VxContext *ctx;
InstanceFactory *factory;

private:
bool opened;
std::shared_ptr<VxToolchain> latest_toolchain;

std::shared_ptr<UIKit::Image> m_ListIcon;
std::shared_ptr<UIKit::Image> m_RefreshIcon;
std::shared_ptr<UIKit::Image> m_AddIcon;
};

#endif // LOGUTILITY_H
11 changes: 11 additions & 0 deletions tools/editor/app/include/editor.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "../instances/instance.h"
#include "../core/ContentBrowser.hpp"
#include "../core/ProjectViewer.hpp"
#include "../core/LogUtility.hpp"
#include "../core/ModuleManager.hpp"
#include "../core/TemplateManager.hpp"
#include "../core/ProjectSettings.hpp"
Expand Down Expand Up @@ -82,6 +83,13 @@ class EditorLayer : public UIKit::Layer
templateManager.OnImGuiRender();
}

if (this->ShowLogUtility)
{
static LogUtility logUtility(this->m_ctx, &factory);
logUtility.OnImGuiRender();
}


for (auto window : moduleDetailsInstances)
{
if (window->render() == "closed")
Expand All @@ -106,6 +114,8 @@ class EditorLayer : public UIKit::Layer
}
}

std::cout << this->m_ctx->registered_logs.size() << std::endl;

PopStyle();
}
void PushStyle()
Expand Down Expand Up @@ -136,6 +146,7 @@ class EditorLayer : public UIKit::Layer
bool ShowModulesManager = false;
bool ShowTemplateManager = false;
bool ShowProjectSettings = false;
bool ShowLogUtility = false;

Instance factory;

Expand Down
7 changes: 7 additions & 0 deletions tools/editor/app/src/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ static void handleShowBottomToolbar()
{
}

static void handleLogUtility()
{
}

static void handleShowSimplifiedHeader(UIKit::Application *app)
{
app->m_Specification.CustomTitlebar = !app->m_Specification.CustomTitlebar;
Expand Down Expand Up @@ -65,6 +69,9 @@ void EditorLayer::menubar(const std::shared_ptr<EditorLayer> &exampleLayer, UIKi
if (ImGui::MenuItem("Project Settings", "Main configurations of this project", &exampleLayer->ShowProjectSettings))
handleProjectSettings();
ImGui::Separator();
if (ImGui::MenuItem("Logs Utility", "Overview of all logs", &exampleLayer->ShowLogUtility))
handleLogUtility();
ImGui::Separator();
if (ImGui::MenuItem("Manage plugins", "Add, remove, edit plugins of this project"))
handleManagePlugins();
if (ImGui::MenuItem("Manage modules", "Manage modules loaded/registered", &exampleLayer->ShowModulesManager))
Expand Down

0 comments on commit 00f932a

Please sign in to comment.