From 154ebea202d64669143ee6bb33f6327d141343c3 Mon Sep 17 00:00:00 2001 From: saturneric Date: Sun, 3 Mar 2024 02:48:44 +0800 Subject: refactor: reduce core prebuild headers and isolate core to modules --- src/core/utils/LogUtils.h | 49 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) (limited to 'src/core/utils/LogUtils.h') diff --git a/src/core/utils/LogUtils.h b/src/core/utils/LogUtils.h index a1a5685a..e8dc6f3b 100644 --- a/src/core/utils/LogUtils.h +++ b/src/core/utils/LogUtils.h @@ -28,6 +28,49 @@ #pragma once +// spdlog library configuration +#undef SPDLOG_ACTIVE_LEVEL +#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE +#include + +// logger fmt +#include "core/GpgFrontendCoreExport.h" + +template <> +struct fmt::formatter { + // Parses format specifications. + constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) { + return ctx.begin(); + } + + // Formats the QString qstr and writes it to the output. + template + auto format(const QString& qstr, FormatContext& ctx) const + -> decltype(ctx.out()) { + // Convert QString to UTF-8 QString (to handle Unicode characters + // correctly) + QByteArray utf8_array = qstr.toUtf8(); + return fmt::format_to(ctx.out(), "{}", utf8_array.constData()); + } +}; + +template <> +struct fmt::formatter { + // Parses format specifications. + constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) { + return ctx.begin(); + } + + // Formats the QString qstr and writes it to the output. + template + auto format(const QByteArray& qarray, FormatContext& ctx) const + -> decltype(ctx.out()) { + // Convert QString to UTF-8 QString (to handle Unicode characters + // correctly) + return fmt::format_to(ctx.out(), "{}", qarray.constData()); + } +}; + namespace GpgFrontend { /** @@ -50,7 +93,7 @@ auto GPGFRONTEND_CORE_EXPORT GetCoreLogger() -> std::shared_ptr; * * @return std::shared_ptr */ -auto GPGFRONTEND_CORE_EXPORT GetLogger(const QString &) +auto GPGFRONTEND_CORE_EXPORT GetLogger(const QString&) -> std::shared_ptr; /** @@ -65,7 +108,7 @@ void GPGFRONTEND_CORE_EXPORT SetDefaultLogLevel(spdlog::level::level_enum); * * @return auto */ -void GPGFRONTEND_CORE_EXPORT RegisterAsyncLogger(const QString &, +void GPGFRONTEND_CORE_EXPORT RegisterAsyncLogger(const QString&, spdlog::level::level_enum); /** @@ -73,7 +116,7 @@ void GPGFRONTEND_CORE_EXPORT RegisterAsyncLogger(const QString &, * * @return auto */ -void GPGFRONTEND_CORE_EXPORT RegisterSyncLogger(const QString &, +void GPGFRONTEND_CORE_EXPORT RegisterSyncLogger(const QString&, spdlog::level::level_enum); } // namespace GpgFrontend -- cgit v1.2.3