]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Log.hh
port new sockets stuff to winsock
[chaz/yoink] / src / Moof / Log.hh
index 324fdeed8555b0c747c1fd8eecacae903496cac7..c09ac017690600fb302cb79a382a5ef55b24750e 100644 (file)
@@ -13,7 +13,7 @@
 #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.
@@ -24,9 +24,9 @@
 
 
 /**
- * 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.
@@ -55,21 +65,71 @@ public:
                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&);
@@ -77,7 +137,7 @@ private:
        static Level    gLevel;
 
        Level                   mLevel;
-       const char*             mType;
+       const char*             mPrefix;
 };
 
 
@@ -93,7 +153,7 @@ template <class T>
 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;
 }
 
 
This page took 0.021618 seconds and 4 git commands to generate.