X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FLog.hh;h=c09ac017690600fb302cb79a382a5ef55b24750e;hp=324fdeed8555b0c747c1fd8eecacae903496cac7;hb=8c6a82feb045ac859b344cd7665a36ac00f4949e;hpb=c85b710e7ead9bc417805bb893571a7139f1081c diff --git a/src/Moof/Log.hh b/src/Moof/Log.hh index 324fdee..c09ac01 100644 --- a/src/Moof/Log.hh +++ b/src/Moof/Log.hh @@ -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 @@ -43,10 +43,20 @@ 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 - void operator () (const T& item) + template + void operator () (const A& a) { - *this << item << std::endl; + *this << a << std::endl; } + template + void operator () (const A& a, const B& b) + { + *this << a << " " << b << std::endl; + } + + template + void operator () (const A& a, const B& b, const C& c) + { + *this << a << " " << b << " " << c << std::endl; + } + + template + void operator () (const A& a, const B& b, const C& c, const D& d) + { + *this << a << " " << b << " " << c << " " << d << std::endl; + } + + template + 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 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 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; }