]> Dogcows Code - chaz/yoink/blobdiff - src/moof/log.hh
fixed documentation about where to find licenses
[chaz/yoink] / src / moof / log.hh
index 2679b37306694763e1b0886a904a660f549f5fff..10691268d56e4d013eed8316b5a04401135b9291 100644 (file)
@@ -1,49 +1,33 @@
 
-/*]  Copyright (c) 2009-2010, Charles McGarvey  [**************************
+/*]  Copyright (c) 2009-2011, Charles McGarvey  [*****************************
 **]  All rights reserved.
 *
-* vi:ts=4 sw=4 tw=75
-*
 * Distributable under the terms and conditions of the 2-clause BSD license;
 * see the file COPYING for a complete text of the license.
 *
-**************************************************************************/
+*****************************************************************************/
 
 #ifndef _MOOF_LOG_HH_
 #define _MOOF_LOG_HH_
 
-/**
- * \file log.hh
- * Functions related to logging the process.
- * The logging functions are log_error(), log_warning(), and log_info(),
- * listed from most critical to least critical.
- */
-
 #include <cstdlib>             // exit
 #include <iostream>
+#include <string>
 
 
-#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
+ * \file log.hh
+ * Functions related to logging the process.  The logging functions are
+ * log_error(), log_warning(), and log_info(), listed from most critical to
+ * least critical.
  */
-#define ASSERT(X) if (!(X)) moof::log_error \
-       << "false assertion at " << __FILE__ << ":" << __LINE__ << ", " \
-       << #X, exit(1)
-#endif
-
 
 namespace moof {
 
 
+// forward declarations
 class script;
 
-
 /**
  * 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
@@ -60,13 +44,13 @@ public:
         */
        enum level
        {
-               none            = 0,            ///< Disable all logging.
-               error           = 1,            ///< Log only errors.
-               warning         = 2,            ///< Log warnings and errors.
-               info            = 3,            ///< Log everything.
+               none            = 0,    ///< Disable all logging.
+               error           = 1,    ///< Log only errors.
+               warning         = 2,    ///< Log warnings and errors.
+               info            = 3,    ///< Log everything.
+               debug           = 4,    ///< Log absolutely everything.
        };
 
-
        /**
         * Set the lowest-priority log message that will be outputted to the
         * log.  Any logging with a lower priority will be ignored.
@@ -81,89 +65,92 @@ public:
         */
        static enum level level();
 
-
        /**
         * Import log functions to a script.
         * \param The script.
         */
        static void import(script& script);
 
-
        /**
         * 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(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>
        void operator () (const A& a,
-                                         const B& b,
-                                         const C& c,
-                                         const D& d,
-                                         const E& e)
+                       const B& b,
+                       const C& c,
+                       const D& d,
+                       const E& e)
        {
-               *this << a << " "
-                         << b << " "
-                         << c << " "
-                         << d << " "
-                         << e << std::endl;
+               *this << a << " " << b << " " << c << " " << d << " " << 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_;
+       enum level              level_;
+       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>
 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.023308 seconds and 4 git commands to generate.