X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Fmoof%2Flog.hh;fp=src%2FMoof%2FLog.hh;h=2679b37306694763e1b0886a904a660f549f5fff;hp=c09ac017690600fb302cb79a382a5ef55b24750e;hb=831f04d4bc19a390415ac0bbac4331c7a65509bc;hpb=299af4f2047e767e5d79501c26444473bda64c64 diff --git a/src/Moof/Log.hh b/src/moof/log.hh similarity index 66% rename from src/Moof/Log.hh rename to src/moof/log.hh index c09ac01..2679b37 100644 --- a/src/Moof/Log.hh +++ b/src/moof/log.hh @@ -9,13 +9,13 @@ * **************************************************************************/ -#ifndef _MOOF_LOG_H_ -#define _MOOF_LOG_H_ +#ifndef _MOOF_LOG_HH_ +#define _MOOF_LOG_HH_ /** - * \file Log.h + * \file log.hh * Functions related to logging the process. - * The logging functions are logError(), logWarning(), and logInfo(), + * The logging functions are log_error(), log_warning(), and log_info(), * listed from most critical to least critical. */ @@ -23,24 +23,25 @@ #include -/** - * Macro which tests an assertion and issues a logError() and exits if the - * assertion is false. - * \param X test to perform - */ - #undef ASSERT - #if NDEBUG #define ASSERT(X) #else -#define ASSERT(X) if (!(X)) Mf::logError \ +/** + * Macro which tests an assertion and issues a log_error() and exits if the + * assertion is false. + * \param X test to perform + */ +#define ASSERT(X) if (!(X)) moof::log_error \ << "false assertion at " << __FILE__ << ":" << __LINE__ << ", " \ << #X, exit(1) #endif -namespace Mf { +namespace moof { + + +class script; /** @@ -50,19 +51,19 @@ namespace Mf { * 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 +class log { public: /** * A type for the level or priority of a log message. */ - enum Level + enum level { - NONE = 0, ///< Disable all logging. - ERRORR = 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. }; @@ -71,14 +72,21 @@ public: * log. Any logging with a lower priority will be ignored. * \param level The log level. */ - static void setLevel(Level level); + static void level(level level); /** * Get the current lowest-priority log level. If unchanged, the - * default level is INFO. + * default level is info. * \return The log level. */ - static Level level(); + static enum level level(); + + + /** + * Import log functions to a script. + * \param The script. + */ + static void import(script& script); /** @@ -86,9 +94,9 @@ public: * \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 */ {} + log(enum level level, const char* prefix) : + level_(level), + prefix_(prefix) /* only pass literal strings */ {} template @@ -132,36 +140,32 @@ public: private: - template friend std::ostream& operator << (Log&, const T&); + template friend std::ostream& operator << (log&, const T&); - static Level gLevel; + static enum level gLevel; - Level mLevel; - const char* mPrefix; + enum level level_; + const char* prefix_; }; extern std::ostream& log; -extern std::ostream& nullLog; +extern std::ostream& null_log; -extern Log logError; -extern Log logWarning; -extern Log logInfo; +extern class log log_error; +extern class log log_warning; +extern class log log_info; template -inline std::ostream& operator << (Log& logObj, const T& item) +inline std::ostream& operator << (class log& log, const T& item) { - if (Log::gLevel < logObj.mLevel) return nullLog; - return log << logObj.mPrefix << item; + if (log::gLevel < log.level_) return null_log; + return moof::log << log.prefix_ << item; } -class Script; -void importLogFunctions(Script& script); - - -} // namespace Mf +} // namespace moof -#endif // _MOOF_LOG_H_ +#endif // _MOOF_LOG_HH_