#pragma once #include #include #include #include #include #include namespace WallpaperEngine::Logging { class Log { public: void addOutput (std::ostream* stream); void addError (std::ostream* stream); template void out (const Data&... data) { std::string str = this->buildBuffer (data...); const std::lock_guard lock (this->mMutex); for (const auto cur : this->mOutputs) { *cur << str << '\n' << std::flush; } } template void debug (const Data&... data) { #if (!NDEBUG) && (!ERRORONLY) std::string str = this->buildBuffer (data...); const std::lock_guard lock (this->mMutex); for (const auto cur : this->mOutputs) { *cur << str << '\n'; } #endif } template void debugerror (const Data&... data) { #if (!NDEBUG) && (ERRORONLY) std::string str = this->buildBuffer (data...); const std::lock_guard lock (this->mMutex); for (const auto cur : this->mOutputs) { *cur << str << '\n'; } #endif } template void error (const Data&... data) { std::string str = this->buildBuffer (data...); const std::lock_guard lock (this->mMutex); for (const auto cur : this->mErrors) { *cur << str << '\n' << std::flush; } } template [[noreturn]] void exception (const Data&... data) { std::string str = this->buildBuffer (data...); { const std::lock_guard lock (this->mMutex); for (const auto cur : this->mErrors) { *cur << str << '\n'; } } throw EX (str); } template [[noreturn]] void exception (const Data&... data) { this->exception (data...); } static Log& get (); private: Log (); template std::string buildBuffer (const Data&... data) { std::stringbuf buffer; std::ostream bufferStream (&buffer); ((bufferStream << data), ...); return buffer.str (); } std::mutex mMutex; std::vector mOutputs = {}; std::vector mErrors = {}; static std::unique_ptr sInstance; }; } #define sLog (WallpaperEngine::Logging::Log::get ())