summaryrefslogtreecommitdiff
path: root/virtual-media/src/logger.hpp
diff options
context:
space:
mode:
authorCzarnowski, Przemyslaw <przemyslaw.hawrylewicz.czarnowski@intel.com>2019-12-20 15:05:42 +0300
committerCzarnowski, Przemyslaw <przemyslaw.hawrylewicz.czarnowski@intel.com>2020-01-10 10:40:17 +0300
commit6d93fe942fe3df101a644ffa39e1e4feab4382e7 (patch)
tree0ccd6d0f7079e5a2c42fc57995455df8f134fe5b /virtual-media/src/logger.hpp
parent5a03fdc6a119b65ecf320622ce2809e340749fa9 (diff)
downloadprovingground-6d93fe942fe3df101a644ffa39e1e4feab4382e7.tar.xz
Entry commit for new VM code
Introducing Virtual Media based on State Machine. - Logging class added - Stub for Main application Change-Id: I05ef576c170e2f9acf90800708f4447452f4050f Signed-off-by: Rapkiewicz, Pawel <pawel.rapkiewicz@intel.com> Signed-off-by: Czarnowski, Przemyslaw <przemyslaw.hawrylewicz.czarnowski@intel.com>
Diffstat (limited to 'virtual-media/src/logger.hpp')
-rw-r--r--virtual-media/src/logger.hpp95
1 files changed, 95 insertions, 0 deletions
diff --git a/virtual-media/src/logger.hpp b/virtual-media/src/logger.hpp
new file mode 100644
index 0000000..1950019
--- /dev/null
+++ b/virtual-media/src/logger.hpp
@@ -0,0 +1,95 @@
+#pragma once
+
+#include <iostream>
+#include <vector>
+
+#define LOG_LEVEL Debug
+
+namespace Logger
+{
+
+struct Struct
+{
+ constexpr static const int32_t value = 6;
+ constexpr static const char* name = "Struct ";
+};
+
+struct Debug
+{
+ constexpr static const int32_t value = 5;
+ constexpr static const char* name = "Debug ";
+};
+
+struct Info
+{
+ constexpr static const int32_t value = 4;
+ constexpr static const char* name = "Info ";
+};
+
+struct Warning
+{
+ constexpr static const int32_t value = 3;
+ constexpr static const char* name = "Warning ";
+};
+
+struct Error
+{
+ constexpr static const int32_t value = 2;
+ constexpr static const char* name = "Error ";
+};
+
+struct Critical
+{
+ constexpr static const int32_t value = 1;
+ constexpr static const char* name = "Critical";
+};
+
+template <std::size_t Len>
+constexpr const char* baseNameImpl(const char (&str)[Len], std::size_t pos)
+{
+ return pos == 0 ? str
+ : (str[pos] == '/' || str[pos] == '\\')
+ ? str + pos + 1
+ : baseNameImpl(str, --pos);
+}
+
+template <std::size_t Len>
+constexpr const char* baseName(const char (&str)[Len])
+{
+ return baseNameImpl(str, Len - 1);
+}
+
+template <typename T>
+std::ostream& operator<<(std::ostream& os, const std::vector<T>& v)
+{
+ for (const auto& i : v)
+ {
+ os << i << " ";
+ }
+ return os;
+}
+
+template <typename DefinedLogLevel, typename LogLevel, typename... Args>
+constexpr void logImpl(const char* file, int32_t line, const char* fname,
+ Args&&... args)
+{
+ if constexpr (LogLevel::value <= DefinedLogLevel::value)
+ {
+ std::cout << "[" << LogLevel::name << "] [" << file << ":" << line
+ << "] " << fname << "(): ";
+ (std::cout << ... << args) << std::endl;
+ }
+}
+
+template <typename LogLevel, typename... Args>
+constexpr void log(const char* file, int32_t line, const char* fname,
+ Args&&... args)
+{
+ logImpl<LOG_LEVEL, LogLevel>(file, line, fname, args...);
+}
+
+#define LogMsg(level, ...) \
+ Logger::log<level>(Logger::baseName(__FILE__), __LINE__, __FUNCTION__, \
+ __VA_ARGS__)
+
+} // namespace Logger