#include <cstdlib> // exit
#include <iostream>
+#include <string>
namespace moof {
error = 1, ///< Log only errors.
warning = 2, ///< Log warnings and errors.
info = 3, ///< Log everything.
+ debug = 4, ///< Log absolutely everything.
};
* \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>
<< 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_;
};
extern std::ostream& log;
extern std::ostream& null_log;
-extern class log log_error;
-extern class log log_warning;
-extern class log log_info;
+extern class log& log_error;
+extern class log& log_warning;
+extern class log& log_info;
+extern class log& log_debug;
template <class T>
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