Library for LoRa communication using MultiTech MDOT.
Fork of libmDot by
Diff: MTS-Utils/MTSLog.h
- Revision:
- 9:ebf682e616d0
- Parent:
- 7:683dba5d576f
- Child:
- 11:9938ba31d428
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MTS-Utils/MTSLog.h Thu Sep 10 13:16:42 2015 -0500 @@ -0,0 +1,99 @@ +/************************************************ + * MultiTech MTDOT Library + * Copyright (c) 2015 MultiTech Systems + * + * See LICENSE file for license information + ***********************************************/ + +#ifndef MTSLOG_H +#define MTSLOG_H + +#ifdef MTS_DEBUG +#define logFatal(format, ...) \ + mts::MTSLog::printMessage(mts::MTSLog::FATAL_LEVEL, "%s:%s:%s| [%s] " format "\r\n", __FILE__, __func__, __LINE__, mts::MTSLog::FATAL_LABEL, ##__VA_ARGS__) +#define logError(format, ...) \ + mts::MTSLog::printMessage(mts::MTSLog::ERROR_LEVEL, "%s:%s:%s| [%s] " format "\r\n", __FILE__, __func__, __LINE__, mts::MTSLog::ERROR_LABEL, ##__VA_ARGS__) +#define logWarning(format, ...) \ + mts::MTSLog::printMessage(mts::MTSLog::WARNING_LEVEL, "%s:%s:%s| [%s] " format "\r\n", __FILE__, __func__, __LINE__, mts::MTSLog::WARNING_LABEL, ##__VA_ARGS__) +#define logInfo(format, ...) \ + mts::MTSLog::printMessage(mts::MTSLog::INFO_LEVEL, "%s:%s:%s| [%s] " format "\r\n", __FILE__, __func__, __LINE__, mts::MTSLog::INFO_LABEL, ##__VA_ARGS__) +#define logDebug(format, ...) \ + mts::MTSLog::printMessage(mts::MTSLog::DEBUG_LEVEL, "%s:%s:%s| [%s] " format "\r\n", __FILE__, __func__, __LINE__, mts::MTSLog::DEBUG_LABEL, ##__VA_ARGS__) +#define logTrace(format, ...) \ + mts::MTSLog::printMessage(mts::MTSLog::TRACE_LEVEL, "%s:%s:%s| [%s] " format "\r\n", __FILE__, __func__, __LINE__, mts::MTSLog::TRACE_LABEL, ##__VA_ARGS__) +#else +#define logFatal(format, ...) \ + mts::MTSLog::printMessage(mts::MTSLog::FATAL_LEVEL, "[%s] " format "\r\n", mts::MTSLog::FATAL_LABEL, ##__VA_ARGS__) +#define logError(format, ...) \ + mts::MTSLog::printMessage(mts::MTSLog::ERROR_LEVEL, "[%s] " format "\r\n", mts::MTSLog::ERROR_LABEL, ##__VA_ARGS__) +#define logWarning(format, ...) \ + mts::MTSLog::printMessage(mts::MTSLog::WARNING_LEVEL, "[%s] " format "\r\n", mts::MTSLog::WARNING_LABEL, ##__VA_ARGS__) +#define logInfo(format, ...) \ + mts::MTSLog::printMessage(mts::MTSLog::INFO_LEVEL, "[%s] " format "\r\n", mts::MTSLog::INFO_LABEL, ##__VA_ARGS__) +#define logDebug(format, ...) \ + mts::MTSLog::printMessage(mts::MTSLog::DEBUG_LEVEL, "[%s] " format "\r\n", mts::MTSLog::DEBUG_LABEL, ##__VA_ARGS__) +#define logTrace(format, ...) \ + mts::MTSLog::printMessage(mts::MTSLog::TRACE_LEVEL, "[%s] " format "\r\n", mts::MTSLog::TRACE_LABEL, ##__VA_ARGS__) +#endif + +namespace mts { + +class MTSLog +{ +public: + + /** Enum of log levels. + */ + enum logLevel { + NONE_LEVEL = 0, + FATAL_LEVEL = 1, + ERROR_LEVEL = 2, + WARNING_LEVEL = 3, + INFO_LEVEL = 4, + DEBUG_LEVEL = 5, + TRACE_LEVEL = 6 + }; + + /** Print log message. + */ + static void printMessage(int level, const char* format, ...); + + /** Determine if the given level is currently printable. + */ + static bool printable(int level); + + /** Set log level + * Messages with lower priority than the current level will not be printed. + * If the level is set to NONE, no messages will print. + */ + static void setLogLevel(int level); + + /** Get the current log level. + */ + static int getLogLevel(); + + /** Get string representation of the current log level. + */ + static const char* getLogLevelString(); + + static const char* NONE_LABEL; + static const char* FATAL_LABEL; + static const char* ERROR_LABEL; + static const char* WARNING_LABEL; + static const char* INFO_LABEL; + static const char* DEBUG_LABEL; + static const char* TRACE_LABEL; + +private: + + /** Constructor + */ + MTSLog(); + + static int currentLevel; + +}; + +} + +#endif