- LOG_NONE = -1, ///< Disable all logging.
- LOG_ERROR = 1, ///< Log only errors.
- LOG_WARNING = 2, ///< Log warnings and errors.
- LOG_INFO = 3, ///< Log info, warnings, errors.
- LOG_DEBUG = 4 ///< Log all messages.
+public:
+
+ /**
+ * A type for the level or priority of a log message.
+ */
+ enum Level
+ {
+ NONE = 0, ///< Disable all logging.
+ ERRORR = 1, ///< Log only errors.
+ WARNING = 2, ///< Log warnings and errors.
+ INFO = 3, ///< Log everything.
+ };
+
+
+ /**
+ * Set the lowest-priority log message that will be outputted to the
+ * log. Any logging with a lower priority will be ignored.
+ * \param level The log level.
+ */
+ static void setLevel(Level level);
+
+ /**
+ * Get the current lowest-priority log level. If unchanged, the
+ * default level is INFO.
+ * \return The log level.
+ */
+ static Level level();
+
+
+ /**
+ * Construct a log with a certain priority and prefix string.
+ * \param level The log level.
+ * \param prefix The string printed before each log message.
+ */
+ Log(Level level, const char* prefix) :
+ mLevel(level),
+ mPrefix(prefix) /* only pass literal strings */ {}
+
+
+ template <class A>
+ void operator () (const A& a)
+ {
+ *this << a << std::endl;
+ }
+
+ template <class A, class B>
+ void operator () (const A& a, const B& b)
+ {
+ *this << a << " " << b << std::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;
+ }
+
+ 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;
+ }
+
+ template <class A, class B, class C, class D, class E>
+ void operator () (const A& a,
+ const B& b,
+ const C& c,
+ const D& d,
+ const E& e)
+ {
+ *this << a << " "
+ << b << " "
+ << c << " "
+ << d << " "
+ << e << std::endl;
+ }
+
+
+private:
+
+ template <class T> friend std::ostream& operator << (Log&, const T&);
+
+ static Level gLevel;
+
+ Level mLevel;
+ const char* mPrefix;