diff --git a/src/MeoAssistant/Logger.hpp b/src/MeoAssistant/Logger.hpp index 590308051c..fee08ac4b4 100644 --- a/src/MeoAssistant/Logger.hpp +++ b/src/MeoAssistant/Logger.hpp @@ -152,49 +152,78 @@ namespace asst m_ofs = std::ofstream(m_log_filename, std::ios::out | std::ios::app); } #ifdef ASST_DEBUG - stream_args(m_ofs, buff, args...); + stream_put_line(m_ofs, buff, args...); #else - stream_args(m_ofs, buff, std::forward(args)...); + stream_put_line(m_ofs, buff, std::forward(args)...); #endif #ifdef ASST_DEBUG - stream_args(std::cout, buff, std::forward(args)...); + stream_put_line(std::cout, buff, std::forward(args)...); #endif } - template - inline void stream_args(std::ostream& os, T&& first, Args&&... rest) + template + struct stream_put_converted_impl { - stream()(os, std::forward(first)); - stream_args(os, std::forward(rest)...); - } - template - inline void stream_args(std::ostream& os) - { - os << std::endl; - } - - template - struct stream - { - inline void operator()(std::ostream& os, T&& first) + static constexpr Stream& apply(Stream& s, T&& value) { - os << first << " "; + s << std::forward(value); + return s; } }; - template - struct stream::value>::type> + + template + struct stream_put_converted_impl>> { - inline void operator()(std::ostream& os, T&& first) + static constexpr Stream& apply(Stream& s, T&& value) { #ifdef _WIN32 - os << utils::utf8_to_ansi(first) << " "; -#else - os << first << " "; // Don't fucking use gbk in linux + s << utils::utf8_to_ansi(std::forward(value)); #endif + return s; } }; + template + struct stream_put_line_impl; + + template + struct stream_put_line_impl { + static constexpr Stream& apply(Stream& s) { + s << std::endl; + return s; + } + }; + + template + struct stream_put_line_impl + { + static constexpr Stream& apply(Stream& s, Only&& only) + { + stream_put_converted_impl::apply(s, std::forward(only)); + s << std::endl; + return s; + } + }; + + template + struct stream_put_line_impl + { + static constexpr Stream& apply(Stream& s, First f, Rest... rs) + { + stream_put_converted_impl::apply(s, std::forward(f)); + s << " "; + stream_put_line_impl::apply(s, std::forward(rs)...); + return s; + } + }; + + template + Stream& stream_put_line(Stream& s, Args... args) + { + return stream_put_line_impl::apply(s, std::forward(args)...); + } + inline static std::string m_dirname; std::mutex m_trace_mutex; std::ofstream m_ofs;