diff options
author | crupest <crupest@outlook.com> | 2020-07-05 23:06:02 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-07-05 23:06:02 +0800 |
commit | 5c805e494425a88da1813902b1ad8a1ab351e30d (patch) | |
tree | be3cfd96dcac19db3e256d610d48b5083c489a6c /include/cru/common/Logger.hpp | |
parent | bbec59718bf8a824583869126762013112f8e568 (diff) | |
download | cru-5c805e494425a88da1813902b1ad8a1ab351e30d.tar.gz cru-5c805e494425a88da1813902b1ad8a1ab351e30d.tar.bz2 cru-5c805e494425a88da1813902b1ad8a1ab351e30d.zip |
...
Diffstat (limited to 'include/cru/common/Logger.hpp')
-rw-r--r-- | include/cru/common/Logger.hpp | 37 |
1 files changed, 7 insertions, 30 deletions
diff --git a/include/cru/common/Logger.hpp b/include/cru/common/Logger.hpp index f76e4626..f83ba8dc 100644 --- a/include/cru/common/Logger.hpp +++ b/include/cru/common/Logger.hpp @@ -15,30 +15,7 @@ enum class LogLevel { Debug, Info, Warn, Error }; struct ILogSource : 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, std::string_view s) = 0; -}; - -class StdioLogSource : public virtual ILogSource { - public: - StdioLogSource() = default; - - CRU_DELETE_COPY(StdioLogSource) - CRU_DELETE_MOVE(StdioLogSource) - - ~StdioLogSource() override = default; - - void Write(LogLevel level, std::string_view s) override { - // TODO: Emmm... Since it is buggy to use narrow char in UTF-8 on Windows. I - // think this implementation might be broken. (However, I didn't test it.) - // Maybe, I should detect Windows and use wide char (And I didn't test this - // either) or other more complicated implementation. Currently, I settled - // with this. - if (level == LogLevel::Error) { - std::cerr << s; - } else { - std::cout << s; - } - } + virtual void Write(LogLevel level, const std::u16string& s) = 0; }; class Logger : public Object { @@ -58,8 +35,8 @@ class Logger : public Object { void RemoveSource(ILogSource* source); public: - void Log(LogLevel level, std::string_view s); - void Log(LogLevel level, std::string_view tag, std::string_view s); + void Log(LogLevel level, std::u16string_view s); + void Log(LogLevel level, std::u16string_view tag, std::u16string_view s); public: std::list<std::unique_ptr<ILogSource>> sources_; @@ -92,7 +69,7 @@ void Error(TArgs&&... args) { } template <typename... TArgs> -void TagDebug([[maybe_unused]] std::string_view tag, +void TagDebug([[maybe_unused]] std::u16string_view tag, [[maybe_unused]] TArgs&&... args) { #ifdef CRU_DEBUG Logger::GetInstance()->Log(LogLevel::Debug, tag, @@ -101,19 +78,19 @@ void TagDebug([[maybe_unused]] std::string_view tag, } template <typename... TArgs> -void TagInfo(std::string_view tag, TArgs&&... args) { +void TagInfo(std::u16string_view tag, TArgs&&... args) { Logger::GetInstance()->Log(LogLevel::Info, tag, fmt::format(std::forward<TArgs>(args)...)); } template <typename... TArgs> -void TagWarn(std::string_view tag, TArgs&&... args) { +void TagWarn(std::u16string_view tag, TArgs&&... args) { Logger::GetInstance()->Log(LogLevel::Warn, tag, fmt::format(std::forward<TArgs>(args)...)); } template <typename... TArgs> -void TagError(std::string_view tag, TArgs&&... args) { +void TagError(std::u16string_view tag, TArgs&&... args) { Logger::GetInstance()->Log(LogLevel::Error, tag, fmt::format(std::forward<TArgs>(args)...)); } |