diff options
author | Yuqian Yang <crupest@crupest.life> | 2025-09-07 11:46:11 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-09-07 11:46:11 +0800 |
commit | a0403d95bea3e3a3eaedf71a0d9c6d4e1316bd8c (patch) | |
tree | b97687f99055b04775b63b7bafd2c909a7074cdb | |
parent | 20123151d12a0b01453ab6a36c84e4d3e5ea9504 (diff) | |
download | cru-a0403d95bea3e3a3eaedf71a0d9c6d4e1316bd8c.tar.gz cru-a0403d95bea3e3a3eaedf71a0d9c6d4e1316bd8c.tar.bz2 cru-a0403d95bea3e3a3eaedf71a0d9c6d4e1316bd8c.zip |
Use std::string in logger.
49 files changed, 173 insertions, 184 deletions
diff --git a/include/cru/base/Base.h b/include/cru/base/Base.h index f8f8c8c0..bd889645 100644 --- a/include/cru/base/Base.h +++ b/include/cru/base/Base.h @@ -117,5 +117,5 @@ inline void hash_combine(std::size_t& s, const T& v) { #define CRU_DEFINE_CLASS_LOG_TAG(tag) \ private: \ - constexpr static const char16_t* kLogTag = tag; + constexpr static const char* kLogTag = tag; } // namespace cru diff --git a/include/cru/base/SubProcess.h b/include/cru/base/SubProcess.h index fbe8ad2b..482edb6e 100644 --- a/include/cru/base/SubProcess.h +++ b/include/cru/base/SubProcess.h @@ -134,7 +134,7 @@ struct IPlatformSubProcessImpl : virtual Interface { * leak. */ class PlatformSubProcess : public Object { - CRU_DEFINE_CLASS_LOG_TAG(u"PlatformSubProcess") + CRU_DEFINE_CLASS_LOG_TAG("PlatformSubProcess") private: struct State { @@ -212,7 +212,7 @@ class PlatformSubProcess : public Object { }; class CRU_BASE_API SubProcess : public Object { - CRU_DEFINE_CLASS_LOG_TAG(u"SubProcess") + CRU_DEFINE_CLASS_LOG_TAG("SubProcess") public: static SubProcess Create( diff --git a/include/cru/base/log/Logger.h b/include/cru/base/log/Logger.h index f77296e1..68352ffd 100644 --- a/include/cru/base/log/Logger.h +++ b/include/cru/base/log/Logger.h @@ -5,6 +5,7 @@ #include "../String.h" #include "../concurrent/ConcurrentQueue.h" +#include <format> #include <memory> #include <mutex> #include <thread> @@ -15,35 +16,26 @@ namespace cru::log { enum class LogLevel { Debug, Info, Warn, Error }; struct CRU_BASE_API LogInfo { - LogInfo(LogLevel level, String tag, String message) + LogInfo(LogLevel level, std::string tag, std::string message) : level(level), tag(std::move(tag)), message(std::move(message)) {} - CRU_DEFAULT_COPY(LogInfo) - CRU_DEFAULT_MOVE(LogInfo) - - ~LogInfo() = default; - LogLevel level; - String tag; - String message; + std::string tag; + std::string message; }; struct CRU_BASE_API ILogTarget : virtual Interface { // Write the string s. LogLevel is just a helper. It has no effect on the // content to write. - virtual void Write(LogLevel level, StringView s) = 0; + virtual void Write(LogLevel level, std::string s) = 0; }; -class CRU_BASE_API Logger : public Object { +class CRU_BASE_API Logger : public Object2 { public: static Logger* GetInstance(); public: Logger(); - - CRU_DELETE_COPY(Logger) - CRU_DELETE_MOVE(Logger) - ~Logger() override; public: @@ -51,17 +43,11 @@ class CRU_BASE_API Logger : public Object { void RemoveLogTarget(ILogTarget* source); public: - void Log(LogLevel level, String tag, String message) { + void Log(LogLevel level, std::string tag, std::string message) { Log(LogInfo(level, std::move(tag), std::move(message))); } void Log(LogInfo log_info); - template <typename... Args> - void FormatLog(LogLevel level, String tag, StringView format, - Args&&... args) { - Log(level, std::move(tag), Format(format, std::forward<Args>(args)...)); - } - private: concurrent::ConcurrentQueue<LogInfo> log_queue_; @@ -73,17 +59,17 @@ class CRU_BASE_API Logger : public Object { class CRU_BASE_API LoggerCppStream : public Object2 { public: - explicit LoggerCppStream(Logger* logger, LogLevel level, String tag); + explicit LoggerCppStream(Logger* logger, LogLevel level, std::string tag); ~LoggerCppStream() override = default; LoggerCppStream WithLevel(LogLevel level) const; - LoggerCppStream WithTag(String tag) const; + LoggerCppStream WithTag(std::string tag) const; private: - void Consume(StringView str); + void Consume(std::string_view str); public: - LoggerCppStream& operator<<(StringView str) { + LoggerCppStream& operator<<(std::string_view str) { this->Consume(str); return *this; } @@ -97,23 +83,23 @@ class CRU_BASE_API LoggerCppStream : public Object2 { private: Logger* logger_; LogLevel level_; - String tag_; + std::string tag_; }; } // namespace cru::log -#define CRU_LOG_TAG_DEBUG(...) \ - cru::log::Logger::GetInstance()->FormatLog(cru::log::LogLevel::Debug, \ - kLogTag, __VA_ARGS__) +#define CRU_LOG_TAG_DEBUG(...) \ + cru::log::Logger::GetInstance()->Log(cru::log::LogLevel::Debug, kLogTag, \ + std::format(__VA_ARGS__)) -#define CRU_LOG_TAG_INFO(...) \ - cru::log::Logger::GetInstance()->FormatLog(cru::log::LogLevel::Info, \ - kLogTag, __VA_ARGS__) +#define CRU_LOG_TAG_INFO(...) \ + cru::log::Logger::GetInstance()->Log(cru::log::LogLevel::Info, kLogTag, \ + std::format(__VA_ARGS__)) -#define CRU_LOG_TAG_WARN(...) \ - cru::log::Logger::GetInstance()->FormatLog(cru::log::LogLevel::Warn, \ - kLogTag, __VA_ARGS__) +#define CRU_LOG_TAG_WARN(...) \ + cru::log::Logger::GetInstance()->Log(cru::log::LogLevel::Warn, kLogTag, \ + std::format(__VA_ARGS__)) -#define CRU_LOG_TAG_ERROR(...) \ - cru::log::Logger::GetInstance()->FormatLog(cru::log::LogLevel::Error, \ - kLogTag, __VA_ARGS__) +#define CRU_LOG_TAG_ERROR(...) \ + cru::log::Logger::GetInstance()->Log(cru::log::LogLevel::Error, kLogTag, \ + std::format(__VA_ARGS__)) diff --git a/include/cru/base/log/StdioLogTarget.h b/include/cru/base/log/StdioLogTarget.h index 4123766b..8f0180ad 100644 --- a/include/cru/base/log/StdioLogTarget.h +++ b/include/cru/base/log/StdioLogTarget.h @@ -5,13 +5,9 @@ namespace cru::log { class StdioLogTarget : public Object, public virtual log::ILogTarget { public: explicit StdioLogTarget(); - - CRU_DELETE_COPY(StdioLogTarget) - CRU_DELETE_MOVE(StdioLogTarget) - ~StdioLogTarget() override; public: - void Write(log::LogLevel level, StringView s) override; + void Write(log::LogLevel level, std::string message) override; }; } // namespace cru::log diff --git a/include/cru/base/platform/unix/PosixSpawnSubProcess.h b/include/cru/base/platform/unix/PosixSpawnSubProcess.h index 8f4bb795..11aa7372 100644 --- a/include/cru/base/platform/unix/PosixSpawnSubProcess.h +++ b/include/cru/base/platform/unix/PosixSpawnSubProcess.h @@ -16,7 +16,7 @@ namespace cru::platform::unix { class PosixSpawnSubProcessImpl : public Object, public virtual IPlatformSubProcessImpl { - CRU_DEFINE_CLASS_LOG_TAG(u"PosixSpawnSubProcess") + CRU_DEFINE_CLASS_LOG_TAG("PosixSpawnSubProcess") public: explicit PosixSpawnSubProcessImpl(); diff --git a/include/cru/platform/graphics/direct2d/Painter.h b/include/cru/platform/graphics/direct2d/Painter.h index 5e0fc92f..c5d5e86a 100644 --- a/include/cru/platform/graphics/direct2d/Painter.h +++ b/include/cru/platform/graphics/direct2d/Painter.h @@ -12,7 +12,7 @@ class CRU_WIN_GRAPHICS_DIRECT_API D2DDeviceContextPainter : public DirectResource, public virtual IPainter, public virtual IComResource<ID2D1DeviceContext1> { - CRU_DEFINE_CLASS_LOG_TAG(u"D2DDeviceContextPainter") + CRU_DEFINE_CLASS_LOG_TAG("D2DDeviceContextPainter") public: explicit D2DDeviceContextPainter(ID2D1DeviceContext1* device_context, bool release = false); diff --git a/include/cru/platform/graphics/quartz/Painter.h b/include/cru/platform/graphics/quartz/Painter.h index 9e21904d..ec0e57af 100644 --- a/include/cru/platform/graphics/quartz/Painter.h +++ b/include/cru/platform/graphics/quartz/Painter.h @@ -11,7 +11,7 @@ namespace cru::platform::graphics::quartz { class QuartzCGContextPainter : public OsxQuartzResource, public virtual IPainter { - CRU_DEFINE_CLASS_LOG_TAG(u"QuartzCGContextPainter") + CRU_DEFINE_CLASS_LOG_TAG("QuartzCGContextPainter") public: explicit QuartzCGContextPainter( diff --git a/include/cru/platform/gui/win/Clipboard.h b/include/cru/platform/gui/win/Clipboard.h index a322d520..ebaa3f4f 100644 --- a/include/cru/platform/gui/win/Clipboard.h +++ b/include/cru/platform/gui/win/Clipboard.h @@ -6,7 +6,7 @@ namespace cru::platform::gui::win { class WinClipboard : public WinNativeResource, public virtual IClipboard { - CRU_DEFINE_CLASS_LOG_TAG(u"WinClipboard") + CRU_DEFINE_CLASS_LOG_TAG("WinClipboard") public: explicit WinClipboard(WinUiApplication* application); diff --git a/include/cru/platform/gui/win/Cursor.h b/include/cru/platform/gui/win/Cursor.h index f9cb0a09..66b0f657 100644 --- a/include/cru/platform/gui/win/Cursor.h +++ b/include/cru/platform/gui/win/Cursor.h @@ -8,7 +8,7 @@ namespace cru::platform::gui::win { class CRU_WIN_GUI_API WinCursor : public WinNativeResource, public virtual ICursor { - CRU_DEFINE_CLASS_LOG_TAG(u"WinCursor") + CRU_DEFINE_CLASS_LOG_TAG("WinCursor") public: WinCursor(HCURSOR handle, bool auto_destroy); diff --git a/include/cru/platform/gui/win/GodWindow.h b/include/cru/platform/gui/win/GodWindow.h index 84fdfcea..05f9a13d 100644 --- a/include/cru/platform/gui/win/GodWindow.h +++ b/include/cru/platform/gui/win/GodWindow.h @@ -9,7 +9,7 @@ namespace cru::platform::gui::win { class CRU_WIN_GUI_API GodWindow : public Object { - CRU_DEFINE_CLASS_LOG_TAG(u"GodWindow") + CRU_DEFINE_CLASS_LOG_TAG("GodWindow") public: explicit GodWindow(WinUiApplication* application); diff --git a/include/cru/platform/gui/win/InputMethod.h b/include/cru/platform/gui/win/InputMethod.h index 3a9faeaa..565a4cd0 100644 --- a/include/cru/platform/gui/win/InputMethod.h +++ b/include/cru/platform/gui/win/InputMethod.h @@ -12,7 +12,7 @@ namespace cru::platform::gui::win { class CRU_WIN_GUI_API AutoHIMC : public Object { - CRU_DEFINE_CLASS_LOG_TAG(u"AutoHIMC") + CRU_DEFINE_CLASS_LOG_TAG("AutoHIMC") public: explicit AutoHIMC(HWND hwnd); @@ -36,7 +36,7 @@ class CRU_WIN_GUI_API AutoHIMC : public Object { class CRU_WIN_GUI_API WinInputMethodContext : public WinNativeResource, public virtual IInputMethodContext { - CRU_DEFINE_CLASS_LOG_TAG(u"WinInputMethodContext") + CRU_DEFINE_CLASS_LOG_TAG("WinInputMethodContext") public: WinInputMethodContext(WinNativeWindow* window); diff --git a/include/cru/platform/gui/win/Window.h b/include/cru/platform/gui/win/Window.h index 292bdee2..74d58228 100644 --- a/include/cru/platform/gui/win/Window.h +++ b/include/cru/platform/gui/win/Window.h @@ -11,7 +11,7 @@ namespace cru::platform::gui::win { class CRU_WIN_GUI_API WinNativeWindow : public WinNativeResource, public virtual INativeWindow { - CRU_DEFINE_CLASS_LOG_TAG(u"WinNativeWindow") + CRU_DEFINE_CLASS_LOG_TAG("WinNativeWindow") public: explicit WinNativeWindow(WinUiApplication* application); diff --git a/include/cru/ui/ThemeResourceDictionary.h b/include/cru/ui/ThemeResourceDictionary.h index c3fcfde2..2ddb4a90 100644 --- a/include/cru/ui/ThemeResourceDictionary.h +++ b/include/cru/ui/ThemeResourceDictionary.h @@ -24,7 +24,7 @@ class CRU_UI_API BadThemeResourceException : public Exception { }; class CRU_UI_API ThemeResourceDictionary : public Object { - CRU_DEFINE_CLASS_LOG_TAG(u"ThemeResources"); + CRU_DEFINE_CLASS_LOG_TAG("ThemeResources"); public: static std::unique_ptr<ThemeResourceDictionary> FromFile( diff --git a/include/cru/ui/controls/Control.h b/include/cru/ui/controls/Control.h index 790f4a3a..f6603bbc 100644 --- a/include/cru/ui/controls/Control.h +++ b/include/cru/ui/controls/Control.h @@ -23,7 +23,7 @@ class CRU_UI_API Control : public Object, public DeleteLaterImpl { friend class RootControl; - CRU_DEFINE_CLASS_LOG_TAG(u"Control") + CRU_DEFINE_CLASS_LOG_TAG("Control") protected: Control(); diff --git a/include/cru/ui/controls/TextHostControlService.h b/include/cru/ui/controls/TextHostControlService.h index 7efd7760..95f7a067 100644 --- a/include/cru/ui/controls/TextHostControlService.h +++ b/include/cru/ui/controls/TextHostControlService.h @@ -77,7 +77,7 @@ class TextControlMovePattern : public Object { }; class CRU_UI_API TextHostControlService : public Object { - CRU_DEFINE_CLASS_LOG_TAG(u"TextControlService") + CRU_DEFINE_CLASS_LOG_TAG("TextControlService") public: TextHostControlService(Control* control); diff --git a/include/cru/ui/helper/ClickDetector.h b/include/cru/ui/helper/ClickDetector.h index 5e30d9c3..ec63b92a 100644 --- a/include/cru/ui/helper/ClickDetector.h +++ b/include/cru/ui/helper/ClickDetector.h @@ -41,7 +41,7 @@ enum class ClickState { }; class ClickDetector : public Object { - CRU_DEFINE_CLASS_LOG_TAG(u"ClickDetector") + CRU_DEFINE_CLASS_LOG_TAG("ClickDetector") public: explicit ClickDetector(controls::Control* control); diff --git a/include/cru/ui/helper/ShortcutHub.h b/include/cru/ui/helper/ShortcutHub.h index 341e76da..19d8c8c9 100644 --- a/include/cru/ui/helper/ShortcutHub.h +++ b/include/cru/ui/helper/ShortcutHub.h @@ -94,7 +94,7 @@ struct ShortcutInfo { }; class CRU_UI_API ShortcutHub : public Object { - CRU_DEFINE_CLASS_LOG_TAG(u"ShortcutHub") + CRU_DEFINE_CLASS_LOG_TAG("ShortcutHub") public: ShortcutHub() = default; diff --git a/include/cru/ui/host/WindowHost.h b/include/cru/ui/host/WindowHost.h index 23229036..e2391125 100644 --- a/include/cru/ui/host/WindowHost.h +++ b/include/cru/ui/host/WindowHost.h @@ -19,7 +19,7 @@ struct AfterLayoutEventArgs {}; // The bridge between control tree and native window. class CRU_UI_API WindowHost : public Object, public SelfResolvable<WindowHost> { friend controls::Control; - CRU_DEFINE_CLASS_LOG_TAG(u"WindowHost") + CRU_DEFINE_CLASS_LOG_TAG("WindowHost") private: static int event_handling_depth_; diff --git a/include/cru/ui/mapper/style/StyleRuleMapper.h b/include/cru/ui/mapper/style/StyleRuleMapper.h index 7430274c..12fcb85b 100644 --- a/include/cru/ui/mapper/style/StyleRuleMapper.h +++ b/include/cru/ui/mapper/style/StyleRuleMapper.h @@ -7,7 +7,7 @@ namespace cru::ui::mapper::style { class CRU_UI_API StyleRuleMapper : public BasicClonablePtrMapper<ui::style::StyleRule> { - CRU_DEFINE_CLASS_LOG_TAG(u"StyleRuleMapper") + CRU_DEFINE_CLASS_LOG_TAG("StyleRuleMapper") public: CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(StyleRuleMapper) diff --git a/include/cru/ui/render/BorderRenderObject.h b/include/cru/ui/render/BorderRenderObject.h index 9f3cff4a..7bfa4290 100644 --- a/include/cru/ui/render/BorderRenderObject.h +++ b/include/cru/ui/render/BorderRenderObject.h @@ -6,7 +6,7 @@ namespace cru::ui::render { class CRU_UI_API BorderRenderObject : public SingleChildRenderObject { - CRU_DEFINE_CLASS_LOG_TAG(u"BorderRenderObject") + CRU_DEFINE_CLASS_LOG_TAG("BorderRenderObject") public: BorderRenderObject(); diff --git a/include/cru/ui/render/FlexLayoutRenderObject.h b/include/cru/ui/render/FlexLayoutRenderObject.h index 4effacb1..6c65ace3 100644 --- a/include/cru/ui/render/FlexLayoutRenderObject.h +++ b/include/cru/ui/render/FlexLayoutRenderObject.h @@ -93,7 +93,7 @@ struct FlexChildLayoutData { // class CRU_UI_API FlexLayoutRenderObject : public LayoutRenderObject<FlexChildLayoutData> { - CRU_DEFINE_CLASS_LOG_TAG(u"FlexLayoutRenderObject") + CRU_DEFINE_CLASS_LOG_TAG("FlexLayoutRenderObject") public: FlexLayoutRenderObject() = default; diff --git a/include/cru/ui/render/RenderObject.h b/include/cru/ui/render/RenderObject.h index 7ab62446..80fa2e10 100644 --- a/include/cru/ui/render/RenderObject.h +++ b/include/cru/ui/render/RenderObject.h @@ -59,7 +59,7 @@ struct BoxConstraint { * content_rect) override; */ class CRU_UI_API RenderObject : public Object { - CRU_DEFINE_CLASS_LOG_TAG(u"RenderObject") + CRU_DEFINE_CLASS_LOG_TAG("RenderObject") protected: RenderObject() = default; diff --git a/include/cru/ui/render/SingleChildRenderObject.h b/include/cru/ui/render/SingleChildRenderObject.h index a98465f0..85442eda 100644 --- a/include/cru/ui/render/SingleChildRenderObject.h +++ b/include/cru/ui/render/SingleChildRenderObject.h @@ -3,7 +3,7 @@ namespace cru::ui::render { class CRU_UI_API SingleChildRenderObject : public RenderObject { - CRU_DEFINE_CLASS_LOG_TAG(u"SingleChildRenderObject") + CRU_DEFINE_CLASS_LOG_TAG("SingleChildRenderObject") public: SingleChildRenderObject() = default; diff --git a/include/cru/ui/render/StackLayoutRenderObject.h b/include/cru/ui/render/StackLayoutRenderObject.h index 4da63ea2..515e8f43 100644 --- a/include/cru/ui/render/StackLayoutRenderObject.h +++ b/include/cru/ui/render/StackLayoutRenderObject.h @@ -28,7 +28,7 @@ struct StackChildLayoutData { // to min size. class CRU_UI_API StackLayoutRenderObject : public LayoutRenderObject<StackChildLayoutData> { - CRU_DEFINE_CLASS_LOG_TAG(u"StackLayoutRenderObject") + CRU_DEFINE_CLASS_LOG_TAG("StackLayoutRenderObject") public: StackLayoutRenderObject() = default; diff --git a/include/cru/ui/render/TextRenderObject.h b/include/cru/ui/render/TextRenderObject.h index 0cb3623d..72958f6f 100644 --- a/include/cru/ui/render/TextRenderObject.h +++ b/include/cru/ui/render/TextRenderObject.h @@ -19,7 +19,7 @@ namespace cru::ui::render { // If the result layout box is bigger than actual text box, then text is center // aligned. class CRU_UI_API TextRenderObject : public RenderObject { - CRU_DEFINE_CLASS_LOG_TAG(u"TextRenderObject") + CRU_DEFINE_CLASS_LOG_TAG("TextRenderObject") public: constexpr static float default_caret_width = 2; diff --git a/include/cru/ui/render/TreeRenderObject.h b/include/cru/ui/render/TreeRenderObject.h index 8c589d7a..ef40f4d0 100644 --- a/include/cru/ui/render/TreeRenderObject.h +++ b/include/cru/ui/render/TreeRenderObject.h @@ -49,7 +49,7 @@ class CRU_UI_API TreeRenderObjectItem : public Object { }; class CRU_UI_API TreeRenderObject : public RenderObject { - CRU_DEFINE_CLASS_LOG_TAG(u"TreeRenderObject") + CRU_DEFINE_CLASS_LOG_TAG("TreeRenderObject") public: TreeRenderObject(); diff --git a/src/base/log/Logger.cpp b/src/base/log/Logger.cpp index 8aa8915c..c195cd87 100644 --- a/src/base/log/Logger.cpp +++ b/src/base/log/Logger.cpp @@ -3,6 +3,7 @@ #include <algorithm> #include <ctime> +#include <format> #ifdef CRU_PLATFORM_WINDOWS #include "cru/base/platform/win/DebugLogTarget.h" @@ -35,32 +36,32 @@ void Logger::RemoveLogTarget(ILogTarget *target) { } namespace { -String LogLevelToString(LogLevel level) { +const char *LogLevelToString(LogLevel level) { switch (level) { case LogLevel::Debug: - return u"DEBUG"; + return "DEBUG"; case LogLevel::Info: - return u"INFO"; + return "INFO"; case LogLevel::Warn: - return u"WARN"; + return "WARN"; case LogLevel::Error: - return u"ERROR"; + return "ERROR"; default: std::terminate(); } } -String GetLogTime() { +std::string GetLogTime() { auto time = std::time(nullptr); auto calendar = std::localtime(&time); - return Format(u"{}:{}:{}", calendar->tm_hour, calendar->tm_min, - calendar->tm_sec); + return std::format("{}:{}:{}", calendar->tm_hour, calendar->tm_min, + calendar->tm_sec); } -String MakeLogFinalMessage(const LogInfo &log_info) { - return Format(u"[{}] {} {}: {}\n", GetLogTime(), - LogLevelToString(log_info.level), log_info.tag, - log_info.message); +std::string MakeLogFinalMessage(const LogInfo &log_info) { + return std::format("[{}] {} {}: {}\n", GetLogTime(), + LogLevelToString(log_info.level), log_info.tag, + log_info.message); } } // namespace @@ -86,18 +87,19 @@ void Logger::Log(LogInfo log_info) { log_queue_.Push(std::move(log_info)); } -LoggerCppStream::LoggerCppStream(Logger *logger, LogLevel level, String tag) +LoggerCppStream::LoggerCppStream(Logger *logger, LogLevel level, + std::string tag) : logger_(logger), level_(level), tag_(std::move(tag)) {} LoggerCppStream LoggerCppStream::WithLevel(LogLevel level) const { return LoggerCppStream(this->logger_, level, this->tag_); } -LoggerCppStream LoggerCppStream::WithTag(String tag) const { +LoggerCppStream LoggerCppStream::WithTag(std::string tag) const { return LoggerCppStream(this->logger_, this->level_, std::move(tag)); } -void LoggerCppStream::Consume(StringView str) { - this->logger_->Log(this->level_, this->tag_, str.ToString()); +void LoggerCppStream::Consume(std::string_view str) { + this->logger_->Log(this->level_, this->tag_, std::string(str)); } } // namespace cru::log diff --git a/src/base/log/StdioLogTarget.cpp b/src/base/log/StdioLogTarget.cpp index 64ddcacc..45203f2c 100644 --- a/src/base/log/StdioLogTarget.cpp +++ b/src/base/log/StdioLogTarget.cpp @@ -7,20 +7,19 @@ StdioLogTarget::StdioLogTarget() {} StdioLogTarget::~StdioLogTarget() {} -void StdioLogTarget::Write(log::LogLevel level, StringView s) { +void StdioLogTarget::Write(log::LogLevel level, std::string message) { #ifdef CRU_PLATFORM_WINDOWS + String s = String::FromUtf8(message); if (level == log::LogLevel::Error) { std::wcerr.write(reinterpret_cast<const wchar_t*>(s.data()), s.size()); } else { std::wcout.write(reinterpret_cast<const wchar_t*>(s.data()), s.size()); } #else - std::string m = s.ToUtf8(); - if (level == log::LogLevel::Error) { - std::cerr << m; + std::cerr << message; } else { - std::cout << m; + std::cout << message; } #endif } diff --git a/src/base/platform/unix/PosixSpawnSubProcess.cpp b/src/base/platform/unix/PosixSpawnSubProcess.cpp index f7d2e855..f99d3224 100644 --- a/src/base/platform/unix/PosixSpawnSubProcess.cpp +++ b/src/base/platform/unix/PosixSpawnSubProcess.cpp @@ -145,14 +145,14 @@ SubProcessExitResult PosixSpawnSubProcessImpl::PlatformWaitForProcess() { while (waitpid(pid_, &wstatus, 0) == -1) { if (errno == EINTR) { - CRU_LOG_TAG_INFO(u"Waitpid is interrupted by a signal. Call it again."); + CRU_LOG_TAG_INFO("Waitpid is interrupted by a signal. Call it again."); continue; } std::unique_ptr<ErrnoException> inner(new ErrnoException(errno)); - throw SubProcessInternalException( - u"Failed to call waitpid on a subprocess.", std::move(inner)); + throw SubProcessInternalException("Failed to call waitpid on a subprocess.", + std::move(inner)); } if (WIFEXITED(wstatus)) { diff --git a/src/base/platform/unix/UnixFile.cpp b/src/base/platform/unix/UnixFile.cpp index 9d4db949..00ed3b9c 100644 --- a/src/base/platform/unix/UnixFile.cpp +++ b/src/base/platform/unix/UnixFile.cpp @@ -19,10 +19,10 @@ UnixFileDescriptor::UnixFileDescriptor(int descriptor, bool auto_close, close_(std::move(close)) {} UnixFileDescriptor::~UnixFileDescriptor() { - constexpr auto kLogTag = u"cru::platform::unix::UnixFileDescriptor"; + constexpr auto kLogTag = "cru::platform::unix::UnixFileDescriptor"; if (this->IsValid() && this->IsAutoClose()) { if (!this->DoClose()) { - CRU_LOG_TAG_ERROR(u"Failed to close file descriptor {}, errno {}.", + CRU_LOG_TAG_ERROR("Failed to close file descriptor {}, errno {}.", descriptor_, errno); } } diff --git a/src/platform/graphics/direct2d/Painter.cpp b/src/platform/graphics/direct2d/Painter.cpp index ec96080a..a505e46e 100644 --- a/src/platform/graphics/direct2d/Painter.cpp +++ b/src/platform/graphics/direct2d/Painter.cpp @@ -22,7 +22,7 @@ D2DDeviceContextPainter::D2DDeviceContextPainter( D2DDeviceContextPainter::~D2DDeviceContextPainter() { if (is_drawing_) { - CRU_LOG_TAG_INFO(u"You may forget to call EndDraw before destroying painter."); + CRU_LOG_TAG_INFO("You may forget to call EndDraw before destroying painter."); } if (release_) { diff --git a/src/platform/gui/osx/Clipboard.mm b/src/platform/gui/osx/Clipboard.mm index db5f6ed3..d87ab7e3 100644 --- a/src/platform/gui/osx/Clipboard.mm +++ b/src/platform/gui/osx/Clipboard.mm @@ -25,7 +25,7 @@ OsxClipboardPrivate::~OsxClipboardPrivate() {} String OsxClipboardPrivate::GetText() { auto result = [pasteboard_ readObjectsForClasses:@[ NSString.class ] options:nil]; if (result == nil) { - CRU_LOG_TAG_WARN(u"Failed to get text from clipboard"); + CRU_LOG_TAG_WARN("Failed to get text from clipboard"); return u""; } else { if (result.count == 0) { diff --git a/src/platform/gui/osx/ClipboardPrivate.h b/src/platform/gui/osx/ClipboardPrivate.h index 766026b6..41554297 100644 --- a/src/platform/gui/osx/ClipboardPrivate.h +++ b/src/platform/gui/osx/ClipboardPrivate.h @@ -7,7 +7,7 @@ namespace cru::platform::gui::osx { namespace details { class OsxClipboardPrivate : public Object { - CRU_DEFINE_CLASS_LOG_TAG(u"OsxClipboardPrivate") + CRU_DEFINE_CLASS_LOG_TAG("OsxClipboardPrivate") public: explicit OsxClipboardPrivate(NSPasteboard* pasteboard); diff --git a/src/platform/gui/win/Clipboard.cpp b/src/platform/gui/win/Clipboard.cpp index 9e305d1c..5525cb40 100644 --- a/src/platform/gui/win/Clipboard.cpp +++ b/src/platform/gui/win/Clipboard.cpp @@ -13,25 +13,25 @@ String WinClipboard::GetText() { auto god_window = application_->GetGodWindow(); if (!::OpenClipboard(god_window->GetHandle())) { - CRU_LOG_TAG_WARN(u"Failed to open clipboard."); + CRU_LOG_TAG_WARN("Failed to open clipboard."); return {}; } if (!::IsClipboardFormatAvailable(CF_UNICODETEXT)) { - CRU_LOG_TAG_WARN(u"Clipboard format for text is not available."); + CRU_LOG_TAG_WARN("Clipboard format for text is not available."); return {}; } auto handle = ::GetClipboardData(CF_UNICODETEXT); if (handle == nullptr) { - CRU_LOG_TAG_WARN(u"Failed to get clipboard data."); + CRU_LOG_TAG_WARN("Failed to get clipboard data."); return {}; } auto ptr = ::GlobalLock(handle); if (ptr == nullptr) { - CRU_LOG_TAG_WARN(u"Failed to lock clipboard data."); + CRU_LOG_TAG_WARN("Failed to lock clipboard data."); ::CloseClipboard(); return {}; } @@ -48,21 +48,21 @@ void WinClipboard::SetText(String text) { auto god_window = application_->GetGodWindow(); if (!::OpenClipboard(god_window->GetHandle())) { - CRU_LOG_TAG_WARN(u"Failed to open clipboard."); + CRU_LOG_TAG_WARN("Failed to open clipboard."); return; } auto handle = GlobalAlloc(GMEM_MOVEABLE, (text.size() + 1) * sizeof(wchar_t)); if (handle == nullptr) { - CRU_LOG_TAG_WARN(u"Failed to allocate clipboard data."); + CRU_LOG_TAG_WARN("Failed to allocate clipboard data."); ::CloseClipboard(); return; } auto ptr = ::GlobalLock(handle); if (ptr == nullptr) { - CRU_LOG_TAG_WARN(u"Failed to lock clipboard data."); + CRU_LOG_TAG_WARN("Failed to lock clipboard data."); ::GlobalFree(handle); ::CloseClipboard(); return; @@ -73,7 +73,7 @@ void WinClipboard::SetText(String text) { ::GlobalUnlock(handle); if (::SetClipboardData(CF_UNICODETEXT, handle) == nullptr) { - CRU_LOG_TAG_WARN(u"Failed to set clipboard data."); + CRU_LOG_TAG_WARN("Failed to set clipboard data."); } ::CloseClipboard(); diff --git a/src/platform/gui/win/Cursor.cpp b/src/platform/gui/win/Cursor.cpp index e6cce5b9..24e9c2fc 100644 --- a/src/platform/gui/win/Cursor.cpp +++ b/src/platform/gui/win/Cursor.cpp @@ -16,7 +16,7 @@ WinCursor::~WinCursor() { if (!::DestroyCursor(handle_)) { // This is not a fetal error but might still need notice because it may // cause leak. - CRU_LOG_TAG_WARN(u"Failed to destroy a cursor. Last error code: {}", + CRU_LOG_TAG_WARN("Failed to destroy a cursor. Last error code: {}", ::GetLastError()); } } diff --git a/src/platform/gui/win/GodWindow.cpp b/src/platform/gui/win/GodWindow.cpp index c969df8f..485eae72 100644 --- a/src/platform/gui/win/GodWindow.cpp +++ b/src/platform/gui/win/GodWindow.cpp @@ -43,7 +43,7 @@ GodWindow::GodWindow(WinUiApplication* application) { GodWindow::~GodWindow() { if (!::DestroyWindow(hwnd_)) { // Although this could be "safely" ignore. - CRU_LOG_TAG_WARN(u"Failed to destroy god window."); + CRU_LOG_TAG_WARN("Failed to destroy god window."); } } diff --git a/src/platform/gui/win/InputMethod.cpp b/src/platform/gui/win/InputMethod.cpp index 306dc3fa..94795c8c 100644 --- a/src/platform/gui/win/InputMethod.cpp +++ b/src/platform/gui/win/InputMethod.cpp @@ -35,7 +35,7 @@ AutoHIMC& AutoHIMC::operator=(AutoHIMC&& other) { AutoHIMC::~AutoHIMC() { if (handle_) { if (!::ImmReleaseContext(hwnd_, handle_)) - CRU_LOG_TAG_WARN(u"Failed to release HIMC."); + CRU_LOG_TAG_WARN("Failed to release HIMC."); } } @@ -156,7 +156,7 @@ WinInputMethodContext::~WinInputMethodContext() {} void WinInputMethodContext::EnableIME() { const auto hwnd = native_window_->GetWindowHandle(); if (::ImmAssociateContextEx(hwnd, nullptr, IACE_DEFAULT) == FALSE) { - CRU_LOG_TAG_WARN(u"Failed to enable ime."); + CRU_LOG_TAG_WARN("Failed to enable ime."); } } @@ -167,21 +167,21 @@ void WinInputMethodContext::DisableIME() { ::ImmNotifyIME(himc.Get(), NI_COMPOSITIONSTR, CPS_COMPLETE, 0); if (::ImmAssociateContextEx(hwnd, nullptr, 0) == FALSE) { - CRU_LOG_TAG_WARN(u"Failed to disable ime."); + CRU_LOG_TAG_WARN("Failed to disable ime."); } } void WinInputMethodContext::CompleteComposition() { auto himc = GetHIMC(); if (!::ImmNotifyIME(himc.Get(), NI_COMPOSITIONSTR, CPS_COMPLETE, 0)) { - CRU_LOG_TAG_WARN(u"Failed to complete composition."); + CRU_LOG_TAG_WARN("Failed to complete composition."); } } void WinInputMethodContext::CancelComposition() { auto himc = GetHIMC(); if (!::ImmNotifyIME(himc.Get(), NI_COMPOSITIONSTR, CPS_CANCEL, 0)) { - CRU_LOG_TAG_WARN(u"Failed to complete composition."); + CRU_LOG_TAG_WARN("Failed to complete composition."); } } @@ -200,7 +200,7 @@ void WinInputMethodContext::SetCandidateWindowPosition(const Point& point) { form.ptCurrentPos = native_window_->DipToPixel(point); if (!::ImmSetCandidateWindow(himc.Get(), &form)) - CRU_LOG_TAG_DEBUG(u"Failed to set input method candidate window position."); + CRU_LOG_TAG_DEBUG("Failed to set input method candidate window position."); } IEvent<std::nullptr_t>* WinInputMethodContext::CompositionStartEvent() { @@ -228,8 +228,8 @@ void WinInputMethodContext::OnWindowNativeMessage( // should only trigger ascci character. If it is a charater from // supplementary planes, it should be handled with ime messages. CRU_LOG_TAG_WARN( - u"A WM_CHAR message for character from supplementary " - u"planes is ignored."); + "A WM_CHAR message for character from supplementary " + "planes is ignored."); } else { if (c != '\b') { // ignore backspace if (c == '\r') c = '\n'; // Change \r to \n @@ -245,8 +245,8 @@ void WinInputMethodContext::OnWindowNativeMessage( composition_event_.Raise(nullptr); auto composition_text = GetCompositionText(); if constexpr (DebugFlags::input_method) { - CRU_LOG_TAG_DEBUG(u"WM_IME_COMPOSITION composition text:\n{}", - composition_text); + CRU_LOG_TAG_DEBUG("WM_IME_COMPOSITION composition text:\n{}", + composition_text); } if (message.l_param & GCS_RESULTSTR) { auto result_string = GetResultString(); @@ -256,14 +256,14 @@ void WinInputMethodContext::OnWindowNativeMessage( } case WM_IME_STARTCOMPOSITION: { if constexpr (DebugFlags::input_method) { - CRU_LOG_TAG_DEBUG(u"WM_IME_STARTCOMPOSITION received."); + CRU_LOG_TAG_DEBUG("WM_IME_STARTCOMPOSITION received."); } composition_start_event_.Raise(nullptr); break; } case WM_IME_ENDCOMPOSITION: { if constexpr (DebugFlags::input_method) { - CRU_LOG_TAG_DEBUG(u"WM_IME_ENDCOMPOSITION received."); + CRU_LOG_TAG_DEBUG("WM_IME_ENDCOMPOSITION received."); } composition_end_event_.Raise(nullptr); break; diff --git a/src/platform/gui/win/Window.cpp b/src/platform/gui/win/Window.cpp index 690e56de..5bd14323 100644 --- a/src/platform/gui/win/Window.cpp +++ b/src/platform/gui/win/Window.cpp @@ -207,7 +207,7 @@ bool WinNativeWindow::ReleaseMouse() { void WinNativeWindow::RequestRepaint() { if constexpr (DebugFlags::paint) { - CRU_LOG_TAG_DEBUG(u"A repaint is requested."); + CRU_LOG_TAG_DEBUG("A repaint is requested."); } if (!::InvalidateRect(hwnd_, nullptr, FALSE)) throw Win32Error(::GetLastError(), u"Failed to invalidate window."); @@ -235,8 +235,8 @@ void WinNativeWindow::SetCursor(std::shared_ptr<ICursor> cursor) { if (!::SetClassLongPtrW(hwnd_, GCLP_HCURSOR, reinterpret_cast<LONG_PTR>(cursor_->GetHandle()))) { CRU_LOG_TAG_WARN( - u"Failed to set cursor because failed to set class long. Last " - u"error code: {}.", + "Failed to set cursor because failed to set class long. Last " + "error code: {}.", ::GetLastError()); return; } @@ -477,7 +477,7 @@ void WinNativeWindow::RecreateWindow() { if (dpi == 0) throw Win32Error(::GetLastError(), u"Failed to get dpi of window."); dpi_ = static_cast<float>(dpi); - CRU_LOG_TAG_DEBUG(u"Dpi of window is {}.", dpi_); + CRU_LOG_TAG_DEBUG("Dpi of window is {}.", dpi_); window_manager->RegisterWindow(hwnd_, this); @@ -507,7 +507,7 @@ void WinNativeWindow::OnPaintInternal() { paint_event_.Raise(nullptr); ValidateRect(hwnd_, nullptr); if constexpr (DebugFlags::paint) { - CRU_LOG_TAG_DEBUG(u"A repaint is finished."); + CRU_LOG_TAG_DEBUG("A repaint is finished."); } } diff --git a/src/ui/ThemeResourceDictionary.cpp b/src/ui/ThemeResourceDictionary.cpp index fff25e09..421723f5 100644 --- a/src/ui/ThemeResourceDictionary.cpp +++ b/src/ui/ThemeResourceDictionary.cpp @@ -47,10 +47,11 @@ void ThemeResourceDictionary::UpdateResourceMap(xml::XmlElementNode* xml_root) { resource_map_[entry.name] = std::move(entry); } else { - CRU_LOG_TAG_DEBUG(u"Ignore unknown element {} of theme.", c->GetTag()); + CRU_LOG_TAG_DEBUG("Ignore unknown element {} of theme.", + c->GetTag().ToUtf8()); } } else { - CRU_LOG_TAG_DEBUG(u"Ignore text or comment node of theme."); + CRU_LOG_TAG_DEBUG("Ignore text or comment node of theme."); } } } diff --git a/src/ui/controls/Control.cpp b/src/ui/controls/Control.cpp index d6770684..3218f185 100644 --- a/src/ui/controls/Control.cpp +++ b/src/ui/controls/Control.cpp @@ -31,7 +31,7 @@ Control::Control() { Control::~Control() { if (host::WindowHost::IsInEventHandling()) { CRU_LOG_TAG_ERROR( - u"Control destroyed during event handling. Please use DeleteLater."); + "Control destroyed during event handling. Please use DeleteLater."); } in_destruction_ = true; diff --git a/src/ui/controls/TextHostControlService.cpp b/src/ui/controls/TextHostControlService.cpp index bc562e88..ace02a46 100644 --- a/src/ui/controls/TextHostControlService.cpp +++ b/src/ui/controls/TextHostControlService.cpp @@ -227,7 +227,7 @@ void TextHostControlService::SetText(String text, bool stop_composition) { void TextHostControlService::InsertText(Index position, StringView text, bool stop_composition) { if (!Utf16IsValidInsertPosition(this->text_, position)) { - CRU_LOG_TAG_ERROR(u"Invalid text insert position."); + CRU_LOG_TAG_ERROR("Invalid text insert position."); return; } this->text_.insert(this->text_.cbegin() + position, text); @@ -240,7 +240,7 @@ void TextHostControlService::InsertText(Index position, StringView text, void TextHostControlService::DeleteChar(Index position, bool stop_composition) { if (!Utf16IsValidInsertPosition(this->text_, position)) { - CRU_LOG_TAG_ERROR(u"Invalid text delete position."); + CRU_LOG_TAG_ERROR("Invalid text delete position."); return; } if (position == static_cast<Index>(this->text_.size())) return; @@ -253,7 +253,7 @@ void TextHostControlService::DeleteChar(Index position, bool stop_composition) { Index TextHostControlService::DeleteCharPrevious(Index position, bool stop_composition) { if (!Utf16IsValidInsertPosition(this->text_, position)) { - CRU_LOG_TAG_ERROR(u"Invalid text delete position."); + CRU_LOG_TAG_ERROR("Invalid text delete position."); return 0; } if (position == 0) return 0; @@ -269,11 +269,11 @@ void TextHostControlService::DeleteText(TextRange range, if (range.count == 0) return; range = range.Normalize(); if (!Utf16IsValidInsertPosition(this->text_, range.GetStart())) { - CRU_LOG_TAG_ERROR(u"Invalid text delete start position."); + CRU_LOG_TAG_ERROR("Invalid text delete start position."); return; } if (!Utf16IsValidInsertPosition(this->text_, range.GetStart())) { - CRU_LOG_TAG_ERROR(u"Invalid text delete end position."); + CRU_LOG_TAG_ERROR("Invalid text delete end position."); return; } this->text_.erase(this->text_.cbegin() + range.GetStart(), @@ -465,7 +465,7 @@ void TextHostControlService::UpdateInputMethodPosition() { right_bottom.y += 5; if constexpr (debug_flags::text_service) { - CRU_LOG_TAG_DEBUG(u"Calculate input method candidate window position: {}.", + CRU_LOG_TAG_DEBUG("Calculate input method candidate window position: {}.", right_bottom); } diff --git a/src/ui/helper/ClickDetector.cpp b/src/ui/helper/ClickDetector.cpp index b7e800a8..2e3dc1a0 100644 --- a/src/ui/helper/ClickDetector.cpp +++ b/src/ui/helper/ClickDetector.cpp @@ -58,7 +58,7 @@ ClickDetector::ClickDetector(controls::Control* control) { this->state_ == ClickState::Hover) { if (!this->control_->CaptureMouse()) { if constexpr (debug_flags::click_detector) { - CRU_LOG_TAG_DEBUG(u"Failed to capture mouse when begin click."); + CRU_LOG_TAG_DEBUG("Failed to capture mouse when begin click."); } return; } @@ -137,7 +137,7 @@ void ClickDetector::SetState(ClickState state) { UnreachableCode(); } }; - CRU_LOG_TAG_DEBUG(u"Click state changed, new state: {}.", to_string(state)); + CRU_LOG_TAG_DEBUG("Click state changed, new state: {}.", to_string(state)); } state_ = state; diff --git a/src/ui/helper/ShortcutHub.cpp b/src/ui/helper/ShortcutHub.cpp index c413ab2a..e3a06e8c 100644 --- a/src/ui/helper/ShortcutHub.cpp +++ b/src/ui/helper/ShortcutHub.cpp @@ -64,7 +64,7 @@ const std::vector<ShortcutInfo>& ShortcutHub::GetShortcutByKeyBind( void ShortcutHub::Install(controls::Control* control) { if (!event_guard_.IsEmpty()) { - CRU_LOG_TAG_ERROR(u"Shortcut hub is already installed. Failed to install."); + CRU_LOG_TAG_ERROR("Shortcut hub is already installed. Failed to install."); return; } @@ -74,7 +74,7 @@ void ShortcutHub::Install(controls::Control* control) { void ShortcutHub::Uninstall() { if (event_guard_.IsEmpty()) { - CRU_LOG_TAG_WARN(u"Shortcut hub is not installed. Failed to uninstall."); + CRU_LOG_TAG_WARN("Shortcut hub is not installed. Failed to uninstall."); return; } @@ -89,17 +89,18 @@ void ShortcutHub::OnKeyDown(events::KeyEventArgs& event) { if constexpr (debug_flags::shortcut) { if (shortcut_list.empty()) { - CRU_LOG_TAG_DEBUG(u"No shortcut for key bind {}.", key_bind.ToString()); + CRU_LOG_TAG_DEBUG("No shortcut for key bind {}.", + key_bind.ToString().ToUtf8()); } - CRU_LOG_TAG_DEBUG(u"Begin to handle shortcut for key bind {}.", - key_bind.ToString()); + CRU_LOG_TAG_DEBUG("Begin to handle shortcut for key bind {}.", + key_bind.ToString()); } for (const auto& shortcut : shortcut_list) { auto is_handled = shortcut.handler(); if (is_handled) { if constexpr (debug_flags::shortcut) { - CRU_LOG_TAG_DEBUG(u"Handle {} handled it.", shortcut.name); + CRU_LOG_TAG_DEBUG("Handle {} handled it.", shortcut.name.ToUtf8()); } handled = true; @@ -108,23 +109,24 @@ void ShortcutHub::OnKeyDown(events::KeyEventArgs& event) { break; } else { if constexpr (debug_flags::shortcut) { - CRU_LOG_TAG_DEBUG(u"Handle {} didn't handle it.", shortcut.name); + CRU_LOG_TAG_DEBUG("Handle {} didn't handle it.", + shortcut.name.ToUtf8()); } } } if constexpr (debug_flags::shortcut) { if (!shortcut_list.empty()) { - CRU_LOG_TAG_DEBUG(u"End handling shortcut for key bind {}.", - key_bind.ToString()); + CRU_LOG_TAG_DEBUG("End handling shortcut for key bind {}.", + key_bind.ToString().ToUtf8()); } } if (!handled) { if constexpr (debug_flags::shortcut) { CRU_LOG_TAG_DEBUG( - u"Raise fallback event for unhandled shortcut of key bind {}.", - key_bind.ToString()); + "Raise fallback event for unhandled shortcut of key bind {}.", + key_bind.ToString().ToUtf8()); } fallback_event_.Raise(event); } diff --git a/src/ui/host/RoutedEventDispatch.h b/src/ui/host/RoutedEventDispatch.h index 6677deea..4efc9208 100644 --- a/src/ui/host/RoutedEventDispatch.h +++ b/src/ui/host/RoutedEventDispatch.h @@ -26,7 +26,7 @@ void DispatchEvent( const String& event_name, controls::Control* const original_sender, events::RoutedEvent<EventArgs>* (controls::Control::*event_ptr)(), controls::Control* const last_receiver, Args&&... args) { - constexpr auto kLogTag = u"DispatchEvent"; + constexpr auto kLogTag = "DispatchEvent"; if (original_sender == nullptr) return; @@ -35,9 +35,9 @@ void DispatchEvent( if (original_sender == last_receiver) { if constexpr (debug_flags::routed_event) CRU_LOG_TAG_DEBUG( - u"Routed event {} no need to dispatch (original_sender == " + "Routed event {} no need to dispatch (original_sender == " "last_receiver). Original sender is {}.", - event_name, original_sender->GetControlType()); + event_name.ToUtf8(), original_sender->GetControlType().ToUtf8()); return; } @@ -54,16 +54,16 @@ void DispatchEvent( } if constexpr (debug_flags::routed_event) { - String log = u"Dispatch routed event "; - log += event_name; - log += u". Path (parent first): "; + std::string log = "Dispatch routed event "; + log += event_name.ToUtf8(); + log += ". Path (parent first): "; auto i = receive_list.crbegin(); const auto end = --receive_list.crend(); for (; i != end; ++i) { - log += i->Resolve()->GetControlType(); - log += u" -> "; + log += i->Resolve()->GetControlType().ToUtf8(); + log += " -> "; } - log += i->Resolve()->GetControlType(); + log += i->Resolve()->GetControlType().ToUtf8(); CRU_LOG_TAG_DEBUG(log); } @@ -83,8 +83,8 @@ void DispatchEvent( handled = true; if constexpr (debug_flags::routed_event) CRU_LOG_TAG_DEBUG( - u"Routed event is short-circuit in TUNNEL at {}-st control (count " - u"from parent).", + "Routed event is short-circuit in TUNNEL at {}-st control (count " + "from parent).", count); break; } @@ -103,8 +103,8 @@ void DispatchEvent( if (event_args.IsHandled()) { if constexpr (debug_flags::routed_event) CRU_LOG_TAG_DEBUG( - u"Routed event is short-circuit in BUBBLE at {}-st control " - u"(count from parent).", + "Routed event is short-circuit in BUBBLE at {}-st control " + "(count from parent).", count); break; } @@ -121,7 +121,7 @@ void DispatchEvent( } if constexpr (debug_flags::routed_event) - CRU_LOG_TAG_DEBUG(u"Routed event dispatch finished."); + CRU_LOG_TAG_DEBUG("Routed event dispatch finished."); WindowHost::LeaveEventHandling(); } diff --git a/src/ui/host/WindowHost.cpp b/src/ui/host/WindowHost.cpp index 9d0e2006..59e383c5 100644 --- a/src/ui/host/WindowHost.cpp +++ b/src/ui/host/WindowHost.cpp @@ -202,7 +202,7 @@ void WindowHost::RelayoutWithSize(const Size& available_size, for (auto& action : after_layout_stable_action_) action(); after_layout_event_.Raise(AfterLayoutEventArgs{}); after_layout_stable_action_.clear(); - if constexpr (debug_flags::layout) CRU_LOG_TAG_DEBUG(u"A relayout is finished."); + if constexpr (debug_flags::layout) CRU_LOG_TAG_DEBUG("A relayout is finished."); } void WindowHost::Repaint() { diff --git a/src/ui/render/BorderRenderObject.cpp b/src/ui/render/BorderRenderObject.cpp index 0e97c5e8..03fdff24 100644 --- a/src/ui/render/BorderRenderObject.cpp +++ b/src/ui/render/BorderRenderObject.cpp @@ -82,11 +82,13 @@ RenderObject* BorderRenderObject::HitTest(const Point& point) { void BorderRenderObject::Draw(platform::graphics::IPainter* painter) { if constexpr (debug_flags::draw) { CRU_LOG_TAG_DEBUG( - u"BorderRenderObject draw, background: {}, foreground: {}.", - background_brush_ == nullptr ? u"NONE" - : background_brush_->GetDebugString(), - foreground_brush_ == nullptr ? u"NONE" - : foreground_brush_->GetDebugString()); + "BorderRenderObject draw, background: {}, foreground: {}.", + background_brush_ == nullptr + ? "NONE" + : background_brush_->GetDebugString().ToUtf8(), + foreground_brush_ == nullptr + ? "NONE" + : foreground_brush_->GetDebugString().ToUtf8()); } if (background_brush_ != nullptr) @@ -95,7 +97,7 @@ void BorderRenderObject::Draw(platform::graphics::IPainter* painter) { if (is_border_enabled_) { if (border_brush_ == nullptr) { - CRU_LOG_TAG_WARN(u"Border is enabled but border brush is null."); + CRU_LOG_TAG_WARN("Border is enabled but border brush is null."); } else { painter->FillGeometry(geometry_.get(), border_brush_.get()); } diff --git a/src/ui/render/FlexLayoutRenderObject.cpp b/src/ui/render/FlexLayoutRenderObject.cpp index 588c379b..efc98602 100644 --- a/src/ui/render/FlexLayoutRenderObject.cpp +++ b/src/ui/render/FlexLayoutRenderObject.cpp @@ -90,7 +90,7 @@ Size FlexLayoutMeasureContentImpl( const MeasureRequirement& requirement, const MeasureSize& preferred_size, const std::vector<RenderObject*>& children, const std::vector<FlexChildLayoutData>& layout_data, - Alignment item_cross_align, String kLogTag) { + Alignment item_cross_align, std::string kLogTag) { Expects(children.size() == layout_data.size()); direction_tag_t direction_tag; @@ -301,7 +301,7 @@ Size FlexLayoutMeasureContentImpl( if (max_main_length.IsSpecified() && total_length > max_main_length.GetLengthOrUndefined()) { CRU_LOG_TAG_WARN( - u"(Measure) Children's main axis length exceeds required max length."); + "(Measure) Children's main axis length exceeds required max length."); total_length = max_main_length.GetLengthOrUndefined(); } else if (min_main_length.IsSpecified() && total_length < min_main_length.GetLengthOrUndefined()) { diff --git a/src/ui/render/RenderObject.cpp b/src/ui/render/RenderObject.cpp index b3a28d6d..1803a131 100644 --- a/src/ui/render/RenderObject.cpp +++ b/src/ui/render/RenderObject.cpp @@ -119,16 +119,16 @@ void RenderObject::Measure(const MeasureRequirement& requirement, preferred_size.OverrideBy(preferred_size_); if constexpr (cru::ui::debug_flags::layout) { - CRU_LOG_TAG_DEBUG(u"{} Measure begins :\nrequirement: {}\npreferred size: {}", - this->GetDebugPathInTree(), requirement.ToDebugString(), - preferred_size.ToDebugString()); + CRU_LOG_TAG_DEBUG("{} Measure begins :\nrequirement: {}\npreferred size: {}", + this->GetDebugPathInTree().ToUtf8(), requirement.ToDebugString().ToUtf8(), + preferred_size.ToDebugString().ToUtf8()); } desired_size_ = OnMeasureCore(merged_requirement, merged_preferred_size); if constexpr (cru::ui::debug_flags::layout) { - CRU_LOG_TAG_DEBUG(u"{} Measure ends :\nresult size: {}", - this->GetDebugPathInTree(), desired_size_); + CRU_LOG_TAG_DEBUG("{} Measure ends :\nresult size: {}", + this->GetDebugPathInTree().ToUtf8(), desired_size_); } Ensures(desired_size_.width >= 0); @@ -144,8 +144,8 @@ Size RenderObject::Measure1(const BoxConstraint& constraint) { void RenderObject::Layout(const Point& offset) { if constexpr (cru::ui::debug_flags::layout) { - CRU_LOG_TAG_DEBUG(u"{} Layout :\noffset: {} size: {}", - this->GetDebugPathInTree(), offset, desired_size_); + CRU_LOG_TAG_DEBUG("{} Layout :\noffset: {} size: {}", + this->GetDebugPathInTree().ToUtf8(), offset, desired_size_); } offset_ = offset; size_ = desired_size_; @@ -192,14 +192,14 @@ Size RenderObject::OnMeasureCore1(const BoxConstraint& constraint) { if (space_size.width > merged_constraint.max.width) { space_size.width = merged_constraint.max.width; - CRU_LOG_TAG_WARN(u"{} space width is over constraint.max.width", - this->GetDebugPathInTree()); + CRU_LOG_TAG_WARN("{} space width is over constraint.max.width", + this->GetDebugPathInTree().ToUtf8()); } if (space_size.height > merged_constraint.max.height) { space_size.height = merged_constraint.max.height; - CRU_LOG_TAG_WARN(u"{} space height is over constraint.max.height", - this->GetDebugPathInTree()); + CRU_LOG_TAG_WARN("{} space height is over constraint.max.height", + this->GetDebugPathInTree().ToUtf8()); } BoxConstraint content_constraint{merged_constraint.max - space_size, diff --git a/src/ui/render/TextRenderObject.cpp b/src/ui/render/TextRenderObject.cpp index 8a579041..346b4957 100644 --- a/src/ui/render/TextRenderObject.cpp +++ b/src/ui/render/TextRenderObject.cpp @@ -178,10 +178,11 @@ RenderObject* TextRenderObject::HitTest(const Point& point) { void TextRenderObject::Draw(platform::graphics::IPainter* painter) { if constexpr (debug_flags::draw) { CRU_LOG_TAG_DEBUG( - u"Begin to paint, total_offset: {}, size: {}, text_layout: " - u"{}, brush: {}.", + "Begin to paint, total_offset: {}, size: {}, text_layout: " + "{}, brush: {}.", this->GetTotalOffset(), this->GetDesiredSize(), - this->text_layout_->GetDebugString(), this->brush_->GetDebugString()); + this->text_layout_->GetDebugString().ToUtf8(), + this->brush_->GetDebugString().ToUtf8()); } if (this->selection_range_.has_value()) { |