Commit 0f1941a7 authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

gui: add better window_logger API

parent 0948a248
......@@ -30,7 +30,7 @@ application::init()
} else {
log_w.log(
3,
"Fail to retrieve home directory. Use current directory instead");
"Fail to retrieve home directory. Use current directory instead\n");
home_dir = std::filesystem::current_path();
}
......@@ -40,7 +40,7 @@ application::init()
log_w.log(
3,
"Fail to retrieve executable directory. Use current directory "
"instead");
"instead\n");
executable_dir = std::filesystem::current_path();
}
......@@ -50,7 +50,7 @@ application::init()
executable_dir.u8string().c_str());
return true;
} catch (const std::exception& /*e*/) {
log_w.log(2, "Fail to initialize application");
log_w.log(2, "Fail to initialize application\n");
return false;
}
}
......
......@@ -21,12 +21,12 @@
namespace irt {
// Forward declaration
struct application;
struct cluster;
struct editor;
struct top_cluster;
struct window_logger;
struct plot_output;
struct file_output;
struct file_discrete_output;
......@@ -46,6 +46,18 @@ using observation_output = std::variant<std::monostate,
file_output_id,
file_discrete_output_id>;
enum class log_status : int
{
emergency,
alert,
critical,
error,
warning,
notice,
info,
debug
};
enum class editor_status
{
editing,
......@@ -426,6 +438,9 @@ struct window_logger
void show(bool* is_show);
};
const char*
log_string(const log_status s) noexcept;
struct application
{
data_array<editor, editor_id> editors;
......
......@@ -14,18 +14,24 @@ window_logger::clear() noexcept
line_offsets.push_back(0);
}
static const char* log_prefix[] = { "[emergency]", "[alert]", "[critical]",
"[error]", "[warning]", "[notice]",
"[info]", "[debug]" };
const char*
log_string(const log_status s) noexcept
{
static const char* str[] = { "[emergency]", "[alert]", "[critical]",
"[error]", "[warning]", "[notice]",
"[info]", "[debug]" };
return str[static_cast<int>(s)];
}
void
window_logger::log(const int level, const char* fmt, ...)
{
auto l = std::clamp(level, 0, 7);
auto old_size = buffer.size();
va_list args;
va_start(args, fmt);
buffer.append(log_prefix[level]);
buffer.append(log_string(enum_cast<log_status>(l)));
buffer.appendfv(fmt, args);
va_end(args);
......@@ -41,8 +47,8 @@ void
window_logger::log(const int level, const char* fmt, va_list args)
{
auto old_size = buffer.size();
buffer.append(log_prefix[level]);
auto l = std::clamp(level, 0, 7);
buffer.append(log_string(enum_cast<log_status>(l)));
buffer.appendfv(fmt, args);
for (auto new_size = buffer.size(); old_size < new_size; ++old_size)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment