Skip to content

Commit

Permalink
Merge pull request #340 from zhujun98/gui
Browse files Browse the repository at this point in the history
Improve GUI logger
  • Loading branch information
zhujun98 authored Aug 29, 2024
2 parents c52c62f + d6bc482 commit d7495cb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion gui/include/graphics/log_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class LogComponent : public Component {

explicit LogComponent(RpcClient* client);

~LogComponent();
~LogComponent() override;

void clear();

Expand Down
8 changes: 4 additions & 4 deletions gui/include/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
#ifndef TOMCAT_LOGGER_HPP
#define TOMCAT_LOGGER_HPP

#include <tuple>
#include <boost/circular_buffer.hpp>

#include <spdlog/spdlog.h>

#include <spdlog/details/null_mutex.h>
#include <spdlog/sinks/base_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h>
Expand Down Expand Up @@ -51,7 +50,8 @@ class GuiLogger {

public:

using BufferType = std::vector<std::tuple<spdlog::level::level_enum, std::string>>;
using BufferType = boost::circular_buffer<std::tuple<spdlog::level::level_enum, std::string>>;
static constexpr size_t BUFFER_SIZE = 100;

private:

Expand All @@ -65,7 +65,7 @@ class GuiLogger {
inline static void init(BufferType& buf) {
auto callback_sink = std::make_shared<details::CallbackSinkMt>(
[&buf](const spdlog::details::log_msg &msg) {
buf.emplace_back(msg.level, std::string(msg.payload.begin(), msg.payload.end()));
buf.push_back({msg.level, std::string(msg.payload.begin(), msg.payload.end())});
});

auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
Expand Down
12 changes: 8 additions & 4 deletions gui/src/graphics/log_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
namespace recastx::gui {

LogComponent::LogComponent(RpcClient* client) :
Component(client), log_levels_({"Debug", "Info" ,"Warn", "Error"}){
Component(client),
log_levels_({"Debug", "Info" ,"Warn", "Error"}),
current_level_(1),
buf_(GuiLogger::BUFFER_SIZE) {
GuiLogger::init(buf_);
log::info("Logging initialized");
}
Expand All @@ -26,9 +29,10 @@ void LogComponent::clear() {

void LogComponent::draw(rpc::ServerState_State) {
ImGui::AlignTextToFramePadding();
ImGui::PushItemWidth(100);
ImGui::Combo("Log levels##LOG_COMP", &current_level_, log_levels_.data(), log_levels_.size());
ImGui::PopItemWidth();
// TODO:
// ImGui::PushItemWidth(100);
// ImGui::Combo("Log levels##LOG_COMP", &current_level_, log_levels_.data(), log_levels_.size());
// ImGui::PopItemWidth();
ImGui::SameLine();
filter_.Draw("Filter", -200.f);
ImGui::SameLine();
Expand Down

0 comments on commit d7495cb

Please sign in to comment.