Library for LoRa communication using MultiTech MDOT.

Fork of libmDot by MultiTech

Committer:
AshuJoshi
Date:
Mon Jul 04 22:28:40 2016 +0000
Revision:
15:50142f513ba8
Removed \r in the Log Format

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AshuJoshi 15:50142f513ba8 1 #ifndef MTSLOG_H
AshuJoshi 15:50142f513ba8 2 #define MTSLOG_H
AshuJoshi 15:50142f513ba8 3
AshuJoshi 15:50142f513ba8 4 #include <string>
AshuJoshi 15:50142f513ba8 5
AshuJoshi 15:50142f513ba8 6 inline const char* className(const std::string& prettyFunction)
AshuJoshi 15:50142f513ba8 7 {
AshuJoshi 15:50142f513ba8 8 size_t colons = prettyFunction.find_last_of("::");
AshuJoshi 15:50142f513ba8 9 if (colons == std::string::npos)
AshuJoshi 15:50142f513ba8 10 return "";
AshuJoshi 15:50142f513ba8 11 size_t begin = prettyFunction.substr(0,colons).rfind(" ") + 1;
AshuJoshi 15:50142f513ba8 12 size_t end = colons - begin;
AshuJoshi 15:50142f513ba8 13
AshuJoshi 15:50142f513ba8 14 return prettyFunction.substr(begin,end).c_str();
AshuJoshi 15:50142f513ba8 15 }
AshuJoshi 15:50142f513ba8 16
AshuJoshi 15:50142f513ba8 17 #define __CLASSNAME__ className(__PRETTY_FUNCTION__)
AshuJoshi 15:50142f513ba8 18
AshuJoshi 15:50142f513ba8 19
AshuJoshi 15:50142f513ba8 20 #ifdef MTS_DEBUG
AshuJoshi 15:50142f513ba8 21 #define logFatal(format, ...) \
AshuJoshi 15:50142f513ba8 22 mts::MTSLog::printMessage(mts::MTSLog::FATAL_LEVEL, "%s:%s:%d| [%s] " format "\r\n", __CLASSNAME__, __func__, __LINE__, mts::MTSLog::FATAL_LABEL, ##__VA_ARGS__)
AshuJoshi 15:50142f513ba8 23 #define logError(format, ...) \
AshuJoshi 15:50142f513ba8 24 mts::MTSLog::printMessage(mts::MTSLog::ERROR_LEVEL, "%s:%s:%d| [%s] " format "\r\n", __CLASSNAME__, __func__, __LINE__, mts::MTSLog::ERROR_LABEL, ##__VA_ARGS__)
AshuJoshi 15:50142f513ba8 25 #define logWarning(format, ...) \
AshuJoshi 15:50142f513ba8 26 mts::MTSLog::printMessage(mts::MTSLog::WARNING_LEVEL, "%s:%s:%d| [%s] " format "\r\n", __CLASSNAME__, __func__, __LINE__, mts::MTSLog::WARNING_LABEL, ##__VA_ARGS__)
AshuJoshi 15:50142f513ba8 27 #define logInfo(format, ...) \
AshuJoshi 15:50142f513ba8 28 mts::MTSLog::printMessage(mts::MTSLog::INFO_LEVEL, "%s:%s:%d| [%s] " format "\r\n", __CLASSNAME__, __func__, __LINE__, mts::MTSLog::INFO_LABEL, ##__VA_ARGS__)
AshuJoshi 15:50142f513ba8 29 #define logDebug(format, ...) \
AshuJoshi 15:50142f513ba8 30 mts::MTSLog::printMessage(mts::MTSLog::DEBUG_LEVEL, "%s:%s:%d| [%s] " format "\r\n", __CLASSNAME__, __func__, __LINE__, mts::MTSLog::DEBUG_LABEL, ##__VA_ARGS__)
AshuJoshi 15:50142f513ba8 31 #define logTrace(format, ...) \
AshuJoshi 15:50142f513ba8 32 mts::MTSLog::printMessage(mts::MTSLog::TRACE_LEVEL, "%s:%s:%d| [%s] " format "\r\n", __CLASSNAME__, __func__, __LINE__, mts::MTSLog::TRACE_LABEL, ##__VA_ARGS__)
AshuJoshi 15:50142f513ba8 33 #else
AshuJoshi 15:50142f513ba8 34 #define logFatal(format, ...) \
AshuJoshi 15:50142f513ba8 35 mts::MTSLog::printMessage(mts::MTSLog::FATAL_LEVEL, "[%s] " format "\r\n", mts::MTSLog::FATAL_LABEL, ##__VA_ARGS__)
AshuJoshi 15:50142f513ba8 36 #define logError(format, ...) \
AshuJoshi 15:50142f513ba8 37 mts::MTSLog::printMessage(mts::MTSLog::ERROR_LEVEL, "[%s] " format "\r\n", mts::MTSLog::ERROR_LABEL, ##__VA_ARGS__)
AshuJoshi 15:50142f513ba8 38 #define logWarning(format, ...) \
AshuJoshi 15:50142f513ba8 39 mts::MTSLog::printMessage(mts::MTSLog::WARNING_LEVEL, "[%s] " format "\r\n", mts::MTSLog::WARNING_LABEL, ##__VA_ARGS__)
AshuJoshi 15:50142f513ba8 40 #define logInfo(format, ...) \
AshuJoshi 15:50142f513ba8 41 mts::MTSLog::printMessage(mts::MTSLog::INFO_LEVEL, "[%s] " format "\r\n", mts::MTSLog::INFO_LABEL, ##__VA_ARGS__)
AshuJoshi 15:50142f513ba8 42 #define logDebug(format, ...) \
AshuJoshi 15:50142f513ba8 43 mts::MTSLog::printMessage(mts::MTSLog::DEBUG_LEVEL, "[%s] " format "\r\n", mts::MTSLog::DEBUG_LABEL, ##__VA_ARGS__)
AshuJoshi 15:50142f513ba8 44 #define logTrace(format, ...) \
AshuJoshi 15:50142f513ba8 45 mts::MTSLog::printMessage(mts::MTSLog::TRACE_LEVEL, "[%s] " format "\r\n", mts::MTSLog::TRACE_LABEL, ##__VA_ARGS__)
AshuJoshi 15:50142f513ba8 46 #endif
AshuJoshi 15:50142f513ba8 47
AshuJoshi 15:50142f513ba8 48 namespace mts {
AshuJoshi 15:50142f513ba8 49
AshuJoshi 15:50142f513ba8 50 class MTSLog
AshuJoshi 15:50142f513ba8 51 {
AshuJoshi 15:50142f513ba8 52 public:
AshuJoshi 15:50142f513ba8 53
AshuJoshi 15:50142f513ba8 54 /** Enum of log levels.
AshuJoshi 15:50142f513ba8 55 */
AshuJoshi 15:50142f513ba8 56 enum logLevel {
AshuJoshi 15:50142f513ba8 57 NONE_LEVEL = 0,
AshuJoshi 15:50142f513ba8 58 FATAL_LEVEL = 1,
AshuJoshi 15:50142f513ba8 59 ERROR_LEVEL = 2,
AshuJoshi 15:50142f513ba8 60 WARNING_LEVEL = 3,
AshuJoshi 15:50142f513ba8 61 INFO_LEVEL = 4,
AshuJoshi 15:50142f513ba8 62 DEBUG_LEVEL = 5,
AshuJoshi 15:50142f513ba8 63 TRACE_LEVEL = 6
AshuJoshi 15:50142f513ba8 64 };
AshuJoshi 15:50142f513ba8 65
AshuJoshi 15:50142f513ba8 66 /** Print log message.
AshuJoshi 15:50142f513ba8 67 */
AshuJoshi 15:50142f513ba8 68 static void printMessage(int level, const char* format, ...);
AshuJoshi 15:50142f513ba8 69
AshuJoshi 15:50142f513ba8 70 /** Determine if the given level is currently printable.
AshuJoshi 15:50142f513ba8 71 */
AshuJoshi 15:50142f513ba8 72 static bool printable(int level);
AshuJoshi 15:50142f513ba8 73
AshuJoshi 15:50142f513ba8 74 /** Set log level
AshuJoshi 15:50142f513ba8 75 * Messages with lower priority than the current level will not be printed.
AshuJoshi 15:50142f513ba8 76 * If the level is set to NONE, no messages will print.
AshuJoshi 15:50142f513ba8 77 */
AshuJoshi 15:50142f513ba8 78 static void setLogLevel(int level);
AshuJoshi 15:50142f513ba8 79
AshuJoshi 15:50142f513ba8 80 /** Get the current log level.
AshuJoshi 15:50142f513ba8 81 */
AshuJoshi 15:50142f513ba8 82 static int getLogLevel();
AshuJoshi 15:50142f513ba8 83
AshuJoshi 15:50142f513ba8 84 /** Get string representation of the current log level.
AshuJoshi 15:50142f513ba8 85 */
AshuJoshi 15:50142f513ba8 86 static const char* getLogLevelString();
AshuJoshi 15:50142f513ba8 87
AshuJoshi 15:50142f513ba8 88 static const char* NONE_LABEL;
AshuJoshi 15:50142f513ba8 89 static const char* FATAL_LABEL;
AshuJoshi 15:50142f513ba8 90 static const char* ERROR_LABEL;
AshuJoshi 15:50142f513ba8 91 static const char* WARNING_LABEL;
AshuJoshi 15:50142f513ba8 92 static const char* INFO_LABEL;
AshuJoshi 15:50142f513ba8 93 static const char* DEBUG_LABEL;
AshuJoshi 15:50142f513ba8 94 static const char* TRACE_LABEL;
AshuJoshi 15:50142f513ba8 95
AshuJoshi 15:50142f513ba8 96 private:
AshuJoshi 15:50142f513ba8 97
AshuJoshi 15:50142f513ba8 98 /** Constructor
AshuJoshi 15:50142f513ba8 99 */
AshuJoshi 15:50142f513ba8 100 MTSLog();
AshuJoshi 15:50142f513ba8 101
AshuJoshi 15:50142f513ba8 102 static int currentLevel;
AshuJoshi 15:50142f513ba8 103
AshuJoshi 15:50142f513ba8 104 };
AshuJoshi 15:50142f513ba8 105
AshuJoshi 15:50142f513ba8 106 }
AshuJoshi 15:50142f513ba8 107
AshuJoshi 15:50142f513ba8 108 #endif