]> Dogcows Code - chaz/yoink/blobdiff - src/moof/log.hh
mesh and other random adjustments
[chaz/yoink] / src / moof / log.hh
index 2679b37306694763e1b0886a904a660f549f5fff..e6e1a80c980400475e4476e271448f5bfdf75e00 100644 (file)
 
 #include <cstdlib>             // exit
 #include <iostream>
-
-
-#undef ASSERT
-#if NDEBUG
-#define ASSERT(X)
-#else
-/**
- * Macro which tests an assertion and issues a log_error() and exits if the
- * assertion is false.
- * \param X test to perform
- */
-#define ASSERT(X) if (!(X)) moof::log_error \
-       << "false assertion at " << __FILE__ << ":" << __LINE__ << ", " \
-       << #X, exit(1)
-#endif
+#include <string>
 
 
 namespace moof {
@@ -94,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>
@@ -134,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       gLevel;
+       static enum level       global_level_;
 
        enum level                      level_;
-       const char*                     prefix_;
+       std::string                     prefix_;
 };
 
 
@@ -160,10 +154,13 @@ extern class log log_info;
 template <class T>
 inline std::ostream& operator << (class log& log, const T& item)
 {
-       if (log::gLevel < log.level_) return null_log;
+       if (log::global_level_ < log.level_) return null_log;
        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.020728 seconds and 4 git commands to generate.