]> Dogcows Code - chaz/yoink/blobdiff - src/moof/log.hh
mesh and other random adjustments
[chaz/yoink] / src / moof / log.hh
index a32daadd8b13b79cc5d8c83dce762d802c67c856..e6e1a80c980400475e4476e271448f5bfdf75e00 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <cstdlib>             // exit
 #include <iostream>
+#include <string>
 
 
 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 <class A>
        void operator () (const A& a)
        {
-               *this << a << std::endl;
+               *this << a << endl;
        }
 
        template <class A, class B>
        void operator () (const A& a, const B& b)
        {
-               *this << a << " " << b << std::endl;
+               *this << a << " " << b << endl;
        }
 
        template <class A, class B, class C>
        void operator () (const A& a, const B& b, const C& c)
        {
-               *this << a << " " << b << " " << c << std::endl;
+               *this << a << " " << b << " " << c << endl;
        }
 
        template <class A, class B, class C, class D>
        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 <class A, class B, class C, class D, class E>
@@ -119,18 +127,19 @@ public:
                          << b << " "
                          << c << " "
                          << d << " "
-                         << e << std::endl;
+                         << e << endl;
        }
 
 
 private:
 
        template <class T> 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
 
This page took 0.019954 seconds and 4 git commands to generate.