#define _MOOF_LOG_H_
/**
- * @file log.h
+ * \file Log.h
* Functions related to logging the process.
* The logging functions are logError(), logWarning(), and logInfo(),
* listed from most critical to least critical.
/**
- * Macro which tests an assertion and issues an logError() and exits if
- * false.
- * @param X test to perform
+ * Macro which tests an assertion and issues a logError() and exits if the
+ * assertion is false.
+ * \param X test to perform
*/
#undef ASSERT
namespace Mf {
+/**
+ * A class for handling a log priority. There are two ways to log
+ * messages: by treating a log object as a function whose parameters are
+ * printed with default spacing, or by treating a log object as an output
+ * stream. Either way, any object can be printed to the log as long as
+ * there is an override for the ostream insertion operator.
+ */
class Log
{
public:
+ /**
+ * A type for the level or priority of a log message.
+ */
enum Level
{
NONE = 0, ///< Disable all logging.
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);
- static Level getLevel();
+ /**
+ * Get the current lowest-priority log level. If unchanged, the
+ * default level is INFO.
+ * \return The log level.
+ */
+ static Level level();
- Log(Level level, const char* type) :
+
+ /**
+ * 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),
- mType(type) /* only pass literal strings */ {}
+ mPrefix(prefix) /* only pass literal strings */ {}
- template <class T>
- void operator () (const T& item)
+ template <class A>
+ void operator () (const A& a)
{
- *this << item << std::endl;
+ *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* mType;
+ const char* mPrefix;
};
inline std::ostream& operator << (Log& logObj, const T& item)
{
if (Log::gLevel < logObj.mLevel) return nullLog;
- return log << logObj.mType << item;
+ return log << logObj.mPrefix << item;
}