SpiecsEngine
 
Loading...
Searching...
No Matches
Console.cpp
Go to the documentation of this file.
1/**
2* @file Console.cpp.
3* @brief The Console Class Implementation.
4* @author Spices.
5*/
6
7#include "Pchheader.h"
8#include "Console.h"
9
10namespace Spices {
11
12 /**
13 * @brief Global Console Pool.
14 */
16
17 Console::Console(const std::string& filePath, uint32_t maxInfos)
18 : m_FilePath(filePath)
19 , m_MaxInfos(maxInfos)
20 {
22
23 m_InfoData.Clear();
24 }
25
26 std::shared_ptr<Console> Console::Registry(const std::string& name, const std::string& filePath)
27 {
29
30 if (m_GlobalConsolePool.find(name) == m_GlobalConsolePool.end())
31 {
32 m_GlobalConsolePool[name] = std::make_shared<Console>(filePath);
33 }
34
35 return m_GlobalConsolePool[name];
36 }
37
38 void Console::Clear()
39 {
41
42 m_InfoData.Clear();
43 }
44
45 void Console::Push(const std::string& cmd)
46 {
48
49 // todo: To be completed.
50 //m_LogInfos.push_back({ cmd , "info", glm::vec4(1.0f)});
51 }
52
53 void Console::sink_it_(const spdlog::details::log_msg& msg)
54 {
56
57 //std::lock_guard<std::mutex> lock(mutex_);
58
59 std::stringstream ss;
60
61 /**
62 * @brief Get Log time.
63 */
64 time_t t = std::chrono::system_clock::to_time_t(msg.time);
65 std::string times = ctime(&t);
66 times.pop_back();
67
68 /**
69 * @brief Get Log level.
70 */
71 InfoLevelHelper helper;
72
73 switch (msg.level)
74 {
75 case spdlog::level::level_enum::trace:
76 helper.level = "trace";
77 helper.color = glm::vec4(0.83f, 0.83f, 0.83f, 1.0f);
78 ss << "[" << times << "] [" << msg.logger_name.data() << "] [" << helper.level << "] " << msg.payload.data();
79 helper.str = ss.str();
80 if (m_InfoData.m_TraceLogInfos.size() == m_MaxInfos)
81 {
82 m_InfoData.m_TraceLogInfos.pop_front();
83 }
84 m_InfoData.m_TraceLogInfos.push_back(helper);
85 break;
86
87 case spdlog::level::level_enum::info:
88 helper.level = "info";
89 helper.color = glm::vec4(0.574f, 0.829f, 1.0f, 1.0f);
90 ss << "[" << times << "] [" << msg.logger_name.data() << "] [" << helper.level << "] " << msg.payload.data();
91 helper.str = ss.str();
92 if (m_InfoData.m_InfoLogInfos.size() == m_MaxInfos)
93 {
94 m_InfoData.m_InfoLogInfos.pop_front();
95 }
96 m_InfoData.m_InfoLogInfos.push_back(helper);
97 break;
98
99 case spdlog::level::level_enum::warn:
100 helper.level = "warn";
101 helper.color = glm::vec4(0.974f, 0.896f, 0.39f, 1.0f);
102 ss << "[" << times << "] [" << msg.logger_name.data() << "] [" << helper.level << "] " << msg.payload.data();
103 helper.str = ss.str();
104 if (m_InfoData.m_WarnLogInfos.size() == m_MaxInfos)
105 {
106 m_InfoData.m_WarnLogInfos.pop_front();
107 }
108 m_InfoData.m_WarnLogInfos.push_back(helper);
109 break;
110
111 case spdlog::level::level_enum::err:
112 helper.level = "error";
113 helper.color = glm::vec4(1.0f, 0.641f, 0.59f, 1.0f);
114 ss << "[" << times << "] [" << msg.logger_name.data() << "] [" << helper.level << "] " << msg.payload.data();
115 helper.str = ss.str();
116 if (m_InfoData.m_ErrorLogInfos.size() == m_MaxInfos)
117 {
118 m_InfoData.m_ErrorLogInfos.pop_front();
119 }
120 m_InfoData.m_ErrorLogInfos.push_back(helper);
121 break;
122
123 case spdlog::level::level_enum::critical:
124 helper.level = "critical";
125 helper.color = glm::vec4(1.0f, 0.0f, 0.0f, 1.0f);
126 ss << "[" << times << "] [" << msg.logger_name.data() << "] [" << helper.level << "] " << msg.payload.data();
127 helper.str = ss.str();
128 if (m_InfoData.m_CriticalLogInfos.size() == m_MaxInfos)
129 {
130 m_InfoData.m_CriticalLogInfos.pop_front();
131 }
132 m_InfoData.m_CriticalLogInfos.push_back(helper);
133 break;
134 }
135 }
136}
#define SPICES_PROFILE_ZONE
static std::shared_ptr< Console > Registry(const std::string &name, const std::string &filePath="")
Registry a console to ConsolePool.
Definition Console.cpp:26
Console(const std::string &filePath, uint32_t maxInfos=50)
Constructor Function.
Definition Console.cpp:17
std::string m_FilePath
Console File Path.
Definition Console.h:150
void Push(const std::string &cmd)
Push a Command to Console.
Definition Console.cpp:45
void Clear()
Clear Console Infos.
Definition Console.cpp:38
void sink_it_(const spdlog::details::log_msg &msg) override
Inherited from spdlog, run when a message pushed.
Definition Console.cpp:53
uint32_t m_MaxInfos
Maximum Num of Information's.
Definition Console.h:155
Console Entity Class.
Definition Console.h:82
static std::unordered_map< std::string, std::shared_ptr< Console > > m_GlobalConsolePool
Global Console Pool.
Definition Console.cpp:15
Help data of specific level of information.
Definition Console.h:19