#pragma once #include #include #include #include class log_stream { public: log_stream(); void log_lines(int n); std::string get_log(); // log to buffer void activate(); // log to plain console void deactivate(); template log_stream& operator<<(const T& arg) { if (m_active) { m_buffer << arg; trim_buffer(); } else { std::cout << arg; } return *this; } log_stream& operator<<( std::basic_ostream& (*func) (std::basic_ostream&) ); private: void trim_buffer(); bool m_active; std::stringstream m_buffer; int m_log_lines; }; extern log_stream log_cout;