Skip to content

Commit

Permalink
[logger] Change it to use qt logger directly
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Sep 3, 2023
1 parent 7c4ad58 commit 91a610f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
35 changes: 35 additions & 0 deletions src/ossia-qt/qt_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <ossia-qt/qt_logger.hpp>

#include <QDebug>
#include <QString>
#include <QStringBuilder>
#include <qobjectdefs.h>
Expand Down Expand Up @@ -138,5 +139,39 @@ QString sanitize_name(QString name, const std::vector<QString>& brethren)
}
}

namespace ossia::qt
{
void log_sink::log(const spdlog::details::log_msg& msg)
{
auto logger
= QMessageLogger(msg.source.filename, msg.source.line, msg.source.funcname);

switch(msg.level)
{
case spdlog::level::level_enum::off:
break;
case spdlog::level::level_enum::trace:
logger.info("[ossia] %.*s", (int)msg.payload.size(), msg.payload.data());
break;
case spdlog::level::level_enum::info:
logger.info("[ossia] %.*s", (int)msg.payload.size(), msg.payload.data());
break;
case spdlog::level::level_enum::debug:
logger.debug("[ossia] %.*s", (int)msg.payload.size(), msg.payload.data());
break;
case spdlog::level::level_enum::warn:
logger.warning("[ossia] %.*s", (int)msg.payload.size(), msg.payload.data());
break;
case spdlog::level::level_enum::err:
logger.critical("[ossia] %.*s", (int)msg.payload.size(), msg.payload.data());
break;
case spdlog::level::level_enum::critical:
logger.critical("[ossia] %.*s", (int)msg.payload.size(), msg.payload.data());
break;
default:
break;
}
}
}
W_OBJECT_IMPL(ossia::qt::log_sink)
ossia::qt::log_sink::~log_sink() = default;
8 changes: 1 addition & 7 deletions src/ossia-qt/qt_logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,8 @@ class OSSIA_EXPORT log_sink final

void set_pattern(const std::string& pattern) override { }
void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) override { }
void log(const spdlog::details::log_msg& msg) override
{
l(msg.level, QString::fromUtf8(msg.payload.data(), msg.payload.size()));
}
void log(const spdlog::details::log_msg& msg) override;

void flush() override { }

void l(spdlog::level::level_enum arg_1, const QString& arg_2)
E_SIGNAL(OSSIA_EXPORT, l, arg_1, arg_2)
};
}

0 comments on commit 91a610f

Please sign in to comment.