X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Fmoof%2Flog.hh;fp=src%2Fmoof%2Flog.hh;h=e6e1a80c980400475e4476e271448f5bfdf75e00;hp=a32daadd8b13b79cc5d8c83dce762d802c67c856;hb=6f1b787a10d8ab1a3117a4b8c004dd2d90599608;hpb=c143f7e806766a73cd69dc6e084e977641019ce6 diff --git a/src/moof/log.hh b/src/moof/log.hh index a32daad..e6e1a80 100644 --- a/src/moof/log.hh +++ b/src/moof/log.hh @@ -21,6 +21,7 @@ #include // exit #include +#include namespace moof { @@ -79,33 +80,40 @@ public: * \param level The log level. * \param prefix The string printed before each log message. */ - log(enum level level, const char* prefix) : - level_(level), - prefix_(prefix) /* only pass literal strings */ {} + log(enum level level); + + + /** + * Output this to end a line. This is equivalent to std::endl except + * this will also reset terminal format attributes. + */ + static struct endl_ + { + } endl; template void operator () (const A& a) { - *this << a << std::endl; + *this << a << endl; } template void operator () (const A& a, const B& b) { - *this << a << " " << b << std::endl; + *this << a << " " << b << endl; } template void operator () (const A& a, const B& b, const C& c) { - *this << a << " " << b << " " << c << std::endl; + *this << a << " " << b << " " << c << endl; } template void operator () (const A& a, const B& b, const C& c, const D& d) { - *this << a << " " << b << " " << c << " " << d << std::endl; + *this << a << " " << b << " " << c << " " << d << endl; } template @@ -119,18 +127,19 @@ public: << b << " " << c << " " << d << " " - << e << std::endl; + << e << endl; } private: template friend std::ostream& operator << (log&, const T&); + friend std::ostream& operator << (log&, endl_); static enum level global_level_; enum level level_; - const char* prefix_; + std::string prefix_; }; @@ -149,6 +158,9 @@ inline std::ostream& operator << (class log& log, const T& item) return moof::log << log.prefix_ << item; } +std::ostream& operator << (class log& log, log::endl_ endl); +std::ostream& operator << (std::ostream& stream, log::endl_ endl); + } // namespace moof