Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of libmDot by
MTSLog.h
00001 #ifndef MTSLOG_H 00002 #define MTSLOG_H 00003 00004 #include <string> 00005 00006 inline const char* className(const std::string& prettyFunction) 00007 { 00008 size_t colons = prettyFunction.find_last_of("::"); 00009 if (colons == std::string::npos) 00010 return ""; 00011 size_t begin = prettyFunction.substr(0,colons).rfind(" ") + 1; 00012 size_t end = colons - begin; 00013 00014 return prettyFunction.substr(begin,end).c_str(); 00015 } 00016 00017 #define __CLASSNAME__ className(__PRETTY_FUNCTION__) 00018 00019 00020 #ifdef MTS_DEBUG 00021 #define logFatal(format, ...) \ 00022 mts::MTSLog::printMessage(mts::MTSLog::FATAL_LEVEL, "%s:%s:%d| [%s] " format "\r\n", __CLASSNAME__, __func__, __LINE__, mts::MTSLog::FATAL_LABEL, ##__VA_ARGS__) 00023 #define logError(format, ...) \ 00024 mts::MTSLog::printMessage(mts::MTSLog::ERROR_LEVEL, "%s:%s:%d| [%s] " format "\r\n", __CLASSNAME__, __func__, __LINE__, mts::MTSLog::ERROR_LABEL, ##__VA_ARGS__) 00025 #define logWarning(format, ...) \ 00026 mts::MTSLog::printMessage(mts::MTSLog::WARNING_LEVEL, "%s:%s:%d| [%s] " format "\r\n", __CLASSNAME__, __func__, __LINE__, mts::MTSLog::WARNING_LABEL, ##__VA_ARGS__) 00027 #define logInfo(format, ...) \ 00028 mts::MTSLog::printMessage(mts::MTSLog::INFO_LEVEL, "%s:%s:%d| [%s] " format "\r\n", __CLASSNAME__, __func__, __LINE__, mts::MTSLog::INFO_LABEL, ##__VA_ARGS__) 00029 #define logDebug(format, ...) \ 00030 mts::MTSLog::printMessage(mts::MTSLog::DEBUG_LEVEL, "%s:%s:%d| [%s] " format "\r\n", __CLASSNAME__, __func__, __LINE__, mts::MTSLog::DEBUG_LABEL, ##__VA_ARGS__) 00031 #define logTrace(format, ...) \ 00032 mts::MTSLog::printMessage(mts::MTSLog::TRACE_LEVEL, "%s:%s:%d| [%s] " format "\r\n", __CLASSNAME__, __func__, __LINE__, mts::MTSLog::TRACE_LABEL, ##__VA_ARGS__) 00033 #else 00034 #define logFatal(format, ...) \ 00035 mts::MTSLog::printMessage(mts::MTSLog::FATAL_LEVEL, "[%s] " format "\r\n", mts::MTSLog::FATAL_LABEL, ##__VA_ARGS__) 00036 #define logError(format, ...) \ 00037 mts::MTSLog::printMessage(mts::MTSLog::ERROR_LEVEL, "[%s] " format "\r\n", mts::MTSLog::ERROR_LABEL, ##__VA_ARGS__) 00038 #define logWarning(format, ...) \ 00039 mts::MTSLog::printMessage(mts::MTSLog::WARNING_LEVEL, "[%s] " format "\r\n", mts::MTSLog::WARNING_LABEL, ##__VA_ARGS__) 00040 #define logInfo(format, ...) \ 00041 mts::MTSLog::printMessage(mts::MTSLog::INFO_LEVEL, "[%s] " format "\r\n", mts::MTSLog::INFO_LABEL, ##__VA_ARGS__) 00042 #define logDebug(format, ...) \ 00043 mts::MTSLog::printMessage(mts::MTSLog::DEBUG_LEVEL, "[%s] " format "\r\n", mts::MTSLog::DEBUG_LABEL, ##__VA_ARGS__) 00044 #define logTrace(format, ...) \ 00045 mts::MTSLog::printMessage(mts::MTSLog::TRACE_LEVEL, "[%s] " format "\r\n", mts::MTSLog::TRACE_LABEL, ##__VA_ARGS__) 00046 #endif 00047 00048 namespace mts { 00049 00050 class MTSLog 00051 { 00052 public: 00053 00054 /** Enum of log levels. 00055 */ 00056 enum logLevel { 00057 NONE_LEVEL = 0, 00058 FATAL_LEVEL = 1, 00059 ERROR_LEVEL = 2, 00060 WARNING_LEVEL = 3, 00061 INFO_LEVEL = 4, 00062 DEBUG_LEVEL = 5, 00063 TRACE_LEVEL = 6 00064 }; 00065 00066 /** Print log message. 00067 */ 00068 static void printMessage(int level, const char* format, ...); 00069 00070 /** Determine if the given level is currently printable. 00071 */ 00072 static bool printable(int level); 00073 00074 /** Set log level 00075 * Messages with lower priority than the current level will not be printed. 00076 * If the level is set to NONE, no messages will print. 00077 */ 00078 static void setLogLevel(int level); 00079 00080 /** Get the current log level. 00081 */ 00082 static int getLogLevel(); 00083 00084 /** Get string representation of the current log level. 00085 */ 00086 static const char* getLogLevelString(); 00087 00088 static const char* NONE_LABEL; 00089 static const char* FATAL_LABEL; 00090 static const char* ERROR_LABEL; 00091 static const char* WARNING_LABEL; 00092 static const char* INFO_LABEL; 00093 static const char* DEBUG_LABEL; 00094 static const char* TRACE_LABEL; 00095 00096 private: 00097 00098 /** Constructor 00099 */ 00100 MTSLog(); 00101 00102 static int currentLevel; 00103 00104 }; 00105 00106 } 00107 00108 #endif
Generated on Tue Jul 12 2022 19:53:49 by
