injectors

main
Brett 2025-03-10 11:27:04 -04:00
parent 2b1086ee15
commit e885df622a
5 changed files with 28 additions and 7 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.20) cmake_minimum_required(VERSION 3.20)
include(cmake/color.cmake) include(cmake/color.cmake)
set(BLT_VERSION 5.2.9) set(BLT_VERSION 5.2.10)
set(BLT_TARGET BLT) set(BLT_TARGET BLT)

View File

@ -160,7 +160,7 @@ namespace blt::logging
size_t m_arg_pos = 0; size_t m_arg_pos = 0;
}; };
void print(const std::string& str); void print(std::string str);
void newline(); void newline();
@ -212,12 +212,13 @@ namespace blt::logging
user_str.pop_back(); user_str.pop_back();
if (level == log_level_t::NONE) if (level == log_level_t::NONE)
{ {
println(user_str); print(user_str);
newline();
return; return;
} }
auto log_fmt_str = config.generate(user_str, get_thread_name(), level, file, line); auto log_fmt_str = config.generate(user_str, get_thread_name(), level, file, line);
if (log_fmt_str) if (log_fmt_str)
print(*log_fmt_str); print(std::move(*log_fmt_str));
} }
namespace detail namespace detail

View File

@ -206,6 +206,11 @@ namespace blt::logging
std::optional<std::string> generate(const std::string& user_str, const std::string& thread_name, log_level_t level, const char* file, std::optional<std::string> generate(const std::string& user_str, const std::string& thread_name, log_level_t level, const char* file,
i32 line) const; i32 line) const;
[[nodiscard]] const std::vector<std::unique_ptr<injector_t>>& get_injectors() const
{
return m_injectors;
}
private: private:
std::vector<std::unique_ptr<injector_t>> m_injectors; std::vector<std::unique_ptr<injector_t>> m_injectors;
// wrappers for streams exist in blt/fs/stream_wrappers.h // wrappers for streams exist in blt/fs/stream_wrappers.h

@ -1 +1 @@
Subproject commit 93201da2ba5a6aba0a6e57ada64973555629b3e3 Subproject commit 7ef2e733416953b222851f9a360d7fc72d068ee5

View File

@ -216,9 +216,24 @@ namespace blt::logging
return get_thread_context().logger; return get_thread_context().logger;
} }
void print(const std::string& str) void print(std::string str)
{ {
std::cout << str; const auto& config = get_global_config();
bool should_print = true;
if (!config.get_injectors().empty())
{
for (const auto& injector : config.get_injectors())
{
auto [new_logging_output, should_continue, should_log] = injector->inject(str);
if (!should_continue)
break;
if (!should_log)
should_print = false;
str = std::move(new_logging_output);
}
}
if (should_print)
std::cout << str;
} }
void newline() void newline()