From 711270dd17bd997644a16d8a6c7e312c6a5ea21d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A6=83=E6=9C=AC=E5=AD=A6?= Date: Thu, 1 Feb 2024 10:46:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E6=97=B6=E9=97=B4=E6=88=B3=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 适配qt的日志格式 %{time yyyy-MM-ddTHH:mm:ss.zzz} ==> %{time}{yyyy-MM-ddTHH:mm:ss.zzz} Log: 修复日志格式时间戳显示异常问题 Bug: https://pms.uniontech.com/bug-view-236239.html Influence: 使用DLogManager的应用日志输出格式 --- src/log/AbstractStringAppender.cpp | 5 +++++ src/log/ConsoleAppender.cpp | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/log/AbstractStringAppender.cpp b/src/log/AbstractStringAppender.cpp index 78ae2199..8cf35185 100644 --- a/src/log/AbstractStringAppender.cpp +++ b/src/log/AbstractStringAppender.cpp @@ -339,6 +339,11 @@ QString AbstractStringAppender::formattedString(const QDateTime &time, Logger::L bool withcolor) const { QString f = format(); + + // dtkcore无法正确解析Qt的日志格式,dtk默认的日志格式并未和Qt统一,解析方式需要兼容两种不同的格式。 + if (f.contains(QLatin1String("time "))) + f.replace(f.indexOf(' ', f.indexOf(QLatin1String("time")) + QLatin1String("time").size()), 1, QLatin1String("}{")); + const int size = f.size(); QString result; diff --git a/src/log/ConsoleAppender.cpp b/src/log/ConsoleAppender.cpp index c89a9c43..6969b5b7 100644 --- a/src/log/ConsoleAppender.cpp +++ b/src/log/ConsoleAppender.cpp @@ -38,7 +38,7 @@ DCORE_BEGIN_NAMESPACE ConsoleAppender::ConsoleAppender() : AbstractStringAppender() - ,m_ignoreEnvPattern(false) + , m_ignoreEnvPattern(false) { if (!spdlog::get("console")) { auto clogger = spdlog::stdout_color_mt("console");