First commit

Fork of libmDot by MultiTech

Revision:
11:9938ba31d428
Parent:
9:ebf682e616d0
--- a/MTS-Utils/MTSLog.h	Thu Sep 10 13:19:35 2015 -0500
+++ b/MTS-Utils/MTSLog.h	Tue Mar 29 10:18:28 2016 -0500
@@ -1,26 +1,35 @@
-/************************************************
- * MultiTech MTDOT Library
- * Copyright (c) 2015 MultiTech Systems
- *
- * See LICENSE file for license information
- ***********************************************/
-
 #ifndef MTSLOG_H
 #define MTSLOG_H
 
+#include <string>
+
+inline const char* className(const std::string& prettyFunction)
+{
+    size_t colons = prettyFunction.find_last_of("::");
+    if (colons == std::string::npos)
+        return "";
+    size_t begin = prettyFunction.substr(0,colons).rfind(" ") + 1;
+    size_t end = colons - begin;
+
+    return prettyFunction.substr(begin,end).c_str();
+}
+
+#define __CLASSNAME__ className(__PRETTY_FUNCTION__)
+
+
 #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__)
+    mts::MTSLog::printMessage(mts::MTSLog::FATAL_LEVEL, "%s:%s:%d| [%s] " format "\r\n", __CLASSNAME__, __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__)
+    mts::MTSLog::printMessage(mts::MTSLog::ERROR_LEVEL, "%s:%s:%d| [%s] " format "\r\n", __CLASSNAME__, __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__)
+    mts::MTSLog::printMessage(mts::MTSLog::WARNING_LEVEL, "%s:%s:%d| [%s] " format "\r\n", __CLASSNAME__, __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__)
+    mts::MTSLog::printMessage(mts::MTSLog::INFO_LEVEL, "%s:%s:%d| [%s] " format "\r\n", __CLASSNAME__, __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__)
+    mts::MTSLog::printMessage(mts::MTSLog::DEBUG_LEVEL, "%s:%s:%d| [%s] " format "\r\n", __CLASSNAME__, __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__)
+    mts::MTSLog::printMessage(mts::MTSLog::TRACE_LEVEL, "%s:%s:%d| [%s] " format "\r\n", __CLASSNAME__, __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__)