42template<
global_state_type Level, fixed_string SourcePath,
int SourceLine, fixed_string Fmt,
typename... Values>
45 static_assert(std::popcount(to_underlying(Level)) == 1);
48 static constexpr char const *log_level_name =
49 Level == global_state_type::log_fatal ?
"fatal" :
50 Level == global_state_type::log_error ?
"error" :
51 Level == global_state_type::log_warning ?
"warning" :
52 Level == global_state_type::log_info ?
"info" :
53 Level == global_state_type::log_debug ?
"debug" :
54 Level == global_state_type::log_trace ?
"trace" :
55 Level == global_state_type::log_audit ?
"audit" :
56 Level == global_state_type::log_statistics ?
"stats" :
57 "<unknown log level>";
63 template<
typename... Args>
64 hi_force_inline
log_message(Args&&...args) noexcept :
65 _time_stamp(time_stamp_count::inplace_with_thread_id{}), _what(std::forward<Args>(args)...)
71 hilet utc_time_point = time_stamp_utc::make(_time_stamp);
72 hilet sys_time_point = std::chrono::clock_cast<std::chrono::system_clock>(utc_time_point);
73 hilet local_time_point = zone->to_local(sys_time_point);
76 hilet thread_id = _time_stamp.thread_id();
79 if constexpr (to_bool(Level & global_state_type::log_statistics)) {
80 return std::format(
"{} {}({}) {:5} {}\n", local_time_point, thread_name,
cpu_id, log_level_name, _what());
82 auto source_filename = std::filesystem::path{
static_cast<std::string_view
>(SourcePath)}.filename().generic_string();
84 "{} {}({}) {:5} {} ({}:{})\n",
97 return std::make_unique<log_message>(*
this);
101 time_stamp_count _time_stamp;
102 delayed_format<Fmt, Values...> _what;
116 template<
global_state_type Level, fixed_string SourcePath,
int SourceLine, fixed_string Fmt,
typename... Args>
117 hi_force_inline
void add(Args&&...args)
noexcept
119 static_assert(std::popcount(to_underlying(Level)) == 1);
122 if (not to_bool(state & Level)) {
134 std::forward<Args>(args)...);
136 if (to_bool(Level & global_state_type::log_fatal) or not to_bool(state & global_state_type::log_is_running)) {
139 [[unlikely]]
flush();
159 return hi::start_subsystem(global_state_type::log_is_running, log::subsystem_init, log::subsystem_deinit);
173 wfree_fifo<detail::log_message_base, 64> _fifo;
184 static inline std::jthread _log_thread;
188 static void log_thread_main(std::stop_token stop_token)
noexcept;
192 static void subsystem_deinit() noexcept;
199 static
bool subsystem_init() noexcept;
T::value_type start_subsystem(T &check_variable, typename T::value_type off_value, typename T::value_type(*init_function)(), void(*deinit_function)())
Start a sub-system.
Definition subsystem.hpp:113
std::atomic< global_state_type > global_state
The global state of the hikogui framework.
Definition global_state.hpp:198