log tweak
This commit is contained in:
parent
161166837f
commit
fec593205b
@ -67,7 +67,7 @@ public:
|
||||
case LogLevel::Info: return LogLevelInfo{ "Info", 0, ImVec4(0.0f, 1.0f, 0.0f, 1.0f) };
|
||||
case LogLevel::Warning: return LogLevelInfo{ "Warning", 1, ImVec4(1.0f, 1.0f, 0.0f, 1.0f) };
|
||||
case LogLevel::Error: return LogLevelInfo{ "Error", 2, ImVec4(1.0f, 0.0f, 0.0f, 1.0f) };
|
||||
case LogLevel::Shutdown: return LogLevelInfo{ "Shutdown", 3, ImVec4(0.0f, 0.0f, 1.0f, 1.0f) };
|
||||
case LogLevel::Shutdown: return LogLevelInfo{ "Shutdown", 3, ImVec4(0.5f, 0.0f, 0.0f, 1.0f) };
|
||||
case LogLevel::Initialize: return LogLevelInfo{ "Initialize", 4, ImVec4(0.0f, 1.0f, 1.0f, 1.0f) };
|
||||
case LogLevel::Update: return LogLevelInfo{ "Update", 5, ImVec4(1.0f, 0.0f, 1.0f, 1.0f) };
|
||||
case LogLevel::Render: return LogLevelInfo{ "Render", 6, ImVec4(1.0f, 1.0f, 1.0f, 1.0f) };
|
||||
@ -105,27 +105,23 @@ public:
|
||||
|
||||
m_logFilePath = directoryPath + "\\" + m_logFileName;
|
||||
|
||||
// enable the 4 first log levels
|
||||
// Enable only the Error warning and shutdown log levels
|
||||
for (int i = 0; i < LogLevelCount; i++)
|
||||
{
|
||||
m_disabledLogLevels[i] = false;
|
||||
m_disabledLogLevels[i] = true;
|
||||
|
||||
if (i > 3)
|
||||
if (i == static_cast<int>(LogLevel::Error) || i == static_cast<int>(LogLevel::Warning) || i == static_cast<int>(LogLevel::Shutdown))
|
||||
{
|
||||
m_disabledLogLevels[i] = true;
|
||||
m_disabledLogLevels[i] = false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ecrit un message dans le fichier de log et le stocke dans le buffer
|
||||
void Log(const std::string& message, const std::string& fileName, int lineNumber, LogLevel level = LogLevel::Info)
|
||||
{
|
||||
// Si le niveau de log est désactivé, ne faites rien
|
||||
if (m_disabledLogLevels[GetLogLevelInfo(level).value])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto in_time_t = std::chrono::system_clock::to_time_t(now);
|
||||
@ -156,6 +152,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
// ecrit un message dans la console
|
||||
void Log(const std::string& message, LogLevel level)
|
||||
{
|
||||
|
||||
@ -216,14 +213,14 @@ public:
|
||||
}
|
||||
|
||||
bool m_disabledLogLevels[LogLevelCount];
|
||||
std::string m_logFilePath;
|
||||
|
||||
private:
|
||||
std::string m_filename;
|
||||
std::string m_appdataPath;
|
||||
std::string m_logFileName;
|
||||
std::string m_logFilePath;
|
||||
|
||||
std::deque<LogEntry> logBuffer;
|
||||
const size_t logBufferSize = 1000;
|
||||
const size_t logBufferSize = 100;
|
||||
|
||||
};
|
||||
|
@ -17,7 +17,7 @@ DockId=0x0000000A,0
|
||||
|
||||
[Window][Terrain]
|
||||
Pos=8,27
|
||||
Size=290,489
|
||||
Size=290,566
|
||||
Collapsed=0
|
||||
DockId=0x00000009,0
|
||||
|
||||
|
@ -526,7 +526,15 @@ void imguiManager::WidgetLogWindow(ApplicationClass* app)
|
||||
|
||||
// Filtre de recherche
|
||||
static ImGuiTextFilter filter;
|
||||
filter.Draw("Filter (inc,-exc)", 180);
|
||||
filter.Draw("Filter ", 180);
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
// Bouton pour ouvrir le fichier de log
|
||||
if (ImGui::Button("Open Log File"))
|
||||
{
|
||||
ShellExecuteA(NULL, "open", Logger::Get().m_logFilePath.c_str(), NULL, NULL, SW_SHOWNORMAL);
|
||||
}
|
||||
|
||||
// Place the menu on the same line as the filter
|
||||
ImGui::SameLine();
|
||||
@ -548,22 +556,19 @@ void imguiManager::WidgetLogWindow(ApplicationClass* app)
|
||||
const auto& logBuffer = Logger::Get().GetLogBuffer();
|
||||
std::vector<Logger::LogEntry> logfiltered;
|
||||
int logCount = logBuffer.size();
|
||||
int filteredLogCount = 0;
|
||||
|
||||
// Affichage des logs filtrés
|
||||
ImGui::BeginChild("Log");
|
||||
|
||||
// Compter le nombre de logs qui passent le filtre et les ajouter a la liste des message a afficher
|
||||
for (const auto& log : logBuffer)
|
||||
{
|
||||
if (filter.PassFilter(log.message.c_str()) && !Logger::Get().m_disabledLogLevels[static_cast<size_t>(log.level)])
|
||||
{
|
||||
logfiltered.push_back(log);
|
||||
filteredLogCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (filteredLogCount == 0)
|
||||
if (logfiltered.size() == 0)
|
||||
{
|
||||
ImGui::Text("No logs to display.");
|
||||
}
|
||||
@ -585,6 +590,12 @@ void imguiManager::WidgetLogWindow(ApplicationClass* app)
|
||||
clipper.End();
|
||||
}
|
||||
|
||||
// Scroll to the bottom
|
||||
if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY())
|
||||
{
|
||||
ImGui::SetScrollHereY(1.0f);
|
||||
}
|
||||
|
||||
ImGui::EndChild();
|
||||
|
||||
ImGui::End();
|
||||
|
Loading…
x
Reference in New Issue
Block a user