diff options
Diffstat (limited to 'include/cru/base')
-rw-r--r-- | include/cru/base/Base.h | 2 | ||||
-rw-r--r-- | include/cru/base/SubProcess.h | 4 | ||||
-rw-r--r-- | include/cru/base/log/Logger.h | 62 | ||||
-rw-r--r-- | include/cru/base/log/StdioLogTarget.h | 6 | ||||
-rw-r--r-- | include/cru/base/platform/unix/PosixSpawnSubProcess.h | 2 |
5 files changed, 29 insertions, 47 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(); |