Enigma  3.2.0
A Simple, Reliable and Efficient Encryption Tool
Logger.hpp
Go to the documentation of this file.
1 #pragma once
2 #ifndef ENIGMA_LOGGER_H
3 #define ENIGMA_LOGGER_H
4 
5 #include <Core/Core.hpp>
6 
7 // Logging Library
8 #pragma warning(push, 0)
9 #include <spdlog/fmt/ostr.h>
10 #include <spdlog/spdlog.h>
11 #pragma warning(pop)
12 
13 
15 
16 class Logger final {
17  ENIGMA_STATIC_CLASS(Logger);
18 
19  public:
23  static void initialize();
24 
28  static void shutdown();
29 
30  public: /* Accessors */
31  static const std::shared_ptr<spdlog::logger>& getLogger() noexcept { return m_logger; }
32 
33  private:
34  inline static std::shared_ptr<spdlog::logger> m_logger{nullptr};
35 };
36 
37 
39 #define ENIGMA_TRACE(...) ::Enigma::Logger::getLogger()->trace(__VA_ARGS__)
40 #define ENIGMA_LOG(...) ::Enigma::Logger::getLogger()->debug(__VA_ARGS__)
41 #define ENIGMA_INFO(...) ::Enigma::Logger::getLogger()->info(__VA_ARGS__)
42 #define ENIGMA_WARN(...) ::Enigma::Logger::getLogger()->warn("{}\n{}:{}\n{}", fmt::format(__VA_ARGS__), __FILE__, __LINE__, ENIGMA_CURRENT_FUNCTION)
43 #define ENIGMA_ERROR(...) ::Enigma::Logger::getLogger()->error("{}\n{}:{}\n{}", fmt::format(__VA_ARGS__), __FILE__, __LINE__, ENIGMA_CURRENT_FUNCTION)
44 #define ENIGMA_CRITICAL(...) ::Enigma::Logger::getLogger()->critical("{}\n{}:{}\n{}", fmt::format(__VA_ARGS__), __FILE__, __LINE__, ENIGMA_CURRENT_FUNCTION)
45 
46 #define ENIGMA_TRACE_IF(condition, ...) \
47  if ((condition)) ENIGMA_TRACE(__VA_ARGS__);
48 #define ENIGMA_LOG_IF(condition, ...) \
49  if ((condition)) ENIGMA_LOG(__VA_ARGS__);
50 #define ENIGMA_INFO_IF(condition, ...) \
51  if ((condition)) ENIGMA_INFO(__VA_ARGS__);
52 #define ENIGMA_WARN_IF(condition, ...) \
53  if ((condition)) ENIGMA_WARN(__VA_ARGS__);
54 #define ENIGMA_ERROR_IF(condition, ...) \
55  if ((condition)) ENIGMA_ERROR(__VA_ARGS__);
56 #define ENIGMA_CRITICAL_IF(condition, ...) \
57  if ((condition)) ENIGMA_CRITICAL(__VA_ARGS__);
58 
59 #define log_trace(...) ENIGMA_TRACE(__VA_ARGS__)
60 #define log_debug(...) ENIGMA_LOG(__VA_ARGS__)
61 #define log_info(...) ENIGMA_INFO(__VA_ARGS__)
62 #define log_warn(...) ENIGMA_WARN(__VA_ARGS__)
63 #define log_error(...) ENIGMA_ERROR(__VA_ARGS__)
64 #define log_critical(...) ENIGMA_CRITICAL(__VA_ARGS__)
65 
66 #define log_trace_if(...) \
67  if ((condition)) ENIGMA_TRACE(__VA_ARGS__);
68 #define log_debug_if(...) \
69  if ((condition)) ENIGMA_LOG(__VA_ARGS__);
70 #define log_info_if(...) \
71  if ((condition)) ENIGMA_INFO(__VA_ARGS__);
72 #define log_warn_if(...) \
73  if ((condition)) ENIGMA_WARN(__VA_ARGS__);
74 #define log_error_if(...) \
75  if ((condition)) ENIGMA_ERROR(__VA_ARGS__);
76 #define log_critical_if(...) \
77  if ((condition)) ENIGMA_CRITICAL(__VA_ARGS__);
78 
79 #define LOG_TRACE(...) ENIGMA_TRACE(__VA_ARGS__)
80 #define LOG_DEBUG(...) ENIGMA_LOG(__VA_ARGS__)
81 #define LOG_INFO(...) ENIGMA_INFO(__VA_ARGS__)
82 #define LOG_WARN(...) ENIGMA_WARN(__VA_ARGS__)
83 #define LOG_ERROR(...) ENIGMA_ERROR(__VA_ARGS__)
84 #define LOG_CRITICAL(...) ENIGMA_CRITICAL(__VA_ARGS__)
85 
86 #define LOG_TRACE_IF(condition, ...) \
87  if ((condition)) ENIGMA_TRACE(__VA_ARGS__);
88 #define LOG_LOG_IF(condition, ...) \
89  if ((condition)) ENIGMA_LOG(__VA_ARGS__);
90 #define LOG_INFO_IF(condition, ...) \
91  if ((condition)) ENIGMA_INFO(__VA_ARGS__);
92 #define LOG_WARN_IF(condition, ...) \
93  if ((condition)) ENIGMA_WARN(__VA_ARGS__);
94 #define LOG_ERROR_IF(condition, ...) \
95  if ((condition)) ENIGMA_ERROR(__VA_ARGS__);
96 #define LOG_CRITICAL_IF(condition, ...) \
97  if ((condition)) ENIGMA_CRITICAL(__VA_ARGS__);
98 
99 
101 
102 #endif // !ENIGMA_LOGGER_H
#define NS_ENIGMA_BEGIN
Enable/Disable Assertions.
Definition: Macros.hpp:13
#define NS_ENIGMA_END
Definition: Macros.hpp:14
static void shutdown()
static void initialize()
static const std::shared_ptr< spdlog::logger > & getLogger() noexcept
Definition: Logger.hpp:31