Utility library for MTS Socket Modem Arduino Shield devices from Multi-Tech Systems

Dependents:   mtsas mtsas thermostat_fan_demo--fan mtsas ... more

NOTE: MTS-Utils has moved to GitHub. This version will not be updated. For updates, go to the GitHub version.

Committer:
Mike Fiore
Date:
Tue Mar 21 15:26:50 2017 -0500
Revision:
15:ae12624eb600
Parent:
14:1d88cf5266c8
update from git revision 37b619a6e4e6e3b49b64c402429cdd8710d960a6

Who changed what in which revision?

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