Mantis App v0.2.8
Loading...
Searching...
No Matches
logging.h
Go to the documentation of this file.
1
8#ifndef MANTIS_LOGGER_H
9#define MANTIS_LOGGER_H
10
11#include <../../3rdParty/json/single_include/nlohmann/json.hpp>
12#include <../../3rdParty/spdlog/include/spdlog/spdlog.h>
13#include <../../3rdParty/spdlog/include/spdlog/sinks/basic_file_sink.h>
14
15namespace mantis
16{
17 using json = nlohmann::json;
18
22 typedef enum class LogLevel : uint8_t
23 {
24 TRACE = 0,
25 DEBUG,
26 INFO,
27 WARN,
30
36 {
37 public:
38 LoggingUnit() = default;
39 ~LoggingUnit() = default;
40
41 static void init();
42 static void setLogLevel(const LogLevel& level = LogLevel::INFO);
43
44 template <typename... Args>
45 static void trace(fmt::format_string<Args...> msg, Args&&... args)
46 {
47 spdlog::trace(msg, std::forward<Args>(args)...);
48 }
49
50 template <typename... Args>
51 static void info(fmt::format_string<Args...> msg, Args&&... args)
52 {
53 spdlog::info(msg, std::forward<Args>(args)...);
54 }
55
56 template <typename... Args>
57 static void debug(fmt::format_string<Args...> msg, Args&&... args)
58 {
59 spdlog::debug(msg, std::forward<Args>(args)...);
60 }
61
62 template <typename... Args>
63 static void warn(fmt::format_string<Args...> msg, Args&&... args)
64 {
65 spdlog::warn(msg, std::forward<Args>(args)...);
66 }
67
68 template <typename... Args>
69 static void critical(fmt::format_string<Args...> msg, Args&&... args)
70 {
71 spdlog::critical(msg, std::forward<Args>(args)...);
72 }
73 };
74
76
82 {
83 public:
84 explicit FuncLogger(const std::string& msg);
85
87
88 private:
89 std::string m_msg;
90 };
91}
92
93// Macro to automatically insert logger with function name
94#define TRACE_CLASS_METHOD() mantis::FuncLogger _logger(std::format("{} {}::{}()", __file__, __class_name__, __func__));
95#define TRACE_METHOD mantis::FuncLogger _logger(std::format("{} {}()", __file__, __func__));
96
97#endif //MANTIS_LOGGER_H
A class for tracing function execution [entry, exit] useful in following execution flow.
Definition logging.h:82
~FuncLogger()
Definition logging.cpp:60
Definition logging.h:36
static void warn(fmt::format_string< Args... > msg, Args &&... args)
Definition logging.h:63
static void trace(fmt::format_string< Args... > msg, Args &&... args)
Definition logging.h:45
static void setLogLevel(const LogLevel &level=LogLevel::INFO)
Definition logging.cpp:9
static void critical(fmt::format_string< Args... > msg, Args &&... args)
Definition logging.h:69
static void init()
Definition logging.cpp:42
static void info(fmt::format_string< Args... > msg, Args &&... args)
Definition logging.h:51
~LoggingUnit()=default
static void debug(fmt::format_string< Args... > msg, Args &&... args)
Definition logging.h:57
nlohmann::json json
Definition mantis.h:35
router.h
Definition app.h:31
LogLevel
Definition logging.h:23
@ WARN
‍Info Logging Level
@ INFO
‍Debug Logging Level
@ CRITICAL
‍Warning Logging Level
@ DEBUG
‍Trace logging level