From 91a610f5914c3c08663a9e1d4831b5117396b91d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Micha=C3=ABl=20Celerier?= Date: Sun, 3 Sep 2023 10:41:56 -0400 Subject: [PATCH] [logger] Change it to use qt logger directly --- src/ossia-qt/qt_logger.cpp | 35 +++++++++++++++++++++++++++++++++++ src/ossia-qt/qt_logger.hpp | 8 +------- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/ossia-qt/qt_logger.cpp b/src/ossia-qt/qt_logger.cpp index f60f579b849..96fe189264d 100644 --- a/src/ossia-qt/qt_logger.cpp +++ b/src/ossia-qt/qt_logger.cpp @@ -4,6 +4,7 @@ #include +#include #include #include #include @@ -138,5 +139,39 @@ QString sanitize_name(QString name, const std::vector& 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; diff --git a/src/ossia-qt/qt_logger.hpp b/src/ossia-qt/qt_logger.hpp index 7612f8d5c4f..8c34f1b3b73 100644 --- a/src/ossia-qt/qt_logger.hpp +++ b/src/ossia-qt/qt_logger.hpp @@ -26,14 +26,8 @@ class OSSIA_EXPORT log_sink final void set_pattern(const std::string& pattern) override { } void set_formatter(std::unique_ptr 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) }; }