adding nesting to debug logs

This commit is contained in:
2024-11-05 12:49:21 +01:00
parent 4ae7bd0420
commit eaf5be3061
16 changed files with 42 additions and 9 deletions

View File

@@ -12,6 +12,10 @@ namespace mlx
};
}
std::uint32_t Logs::s_nesting = 0;
constexpr int LOGS_TABS_WIDTH = 4;
void Logs::Report(LogType type, std::string message)
{
Report(type, 0, {}, {}, std::move(message));
@@ -38,7 +42,14 @@ namespace mlx
switch(type)
{
case LogType::Debug: std::cout << Ansi::blue << "[MLX Debug] " << Ansi::def << code_infos << message << '\n'; break;
case LogType::Debug:
{
std::cout << Ansi::blue << "[MLX Debug] " << Ansi::def << std::flush;
std::printf("%*s", s_nesting * LOGS_TABS_WIDTH, "");
std::fflush(stdout);
std::cout << code_infos << message << std::endl;
break;
}
case LogType::Message: std::cout << Ansi::blue << "[MLX Message] " << Ansi::def << code_infos << message << '\n'; break;
case LogType::Warning: std::cout << Ansi::magenta << "[MLX Warning] " << Ansi::def << code_infos << message << '\n'; break;
case LogType::Error: std::cerr << Ansi::red << "[MLX Error] " << Ansi::def << code_infos << message << '\n'; break;
@@ -52,4 +63,15 @@ namespace mlx
EventBus::Send("__MlxApplication", Internal::FatalErrorEvent{});
}
}
void Logs::BeginSection()
{
s_nesting++;
}
void Logs::EndSection()
{
if(s_nesting > 0)
s_nesting--;
}
}