7#include "delayed_format.hpp"
8#include "format_check.hpp"
9#include "../container/container.hpp"
10#include "../time/time.hpp"
11#include "../utility/utility.hpp"
12#include "../concurrency/concurrency.hpp"
13#include "../char_maps/char_maps.hpp"
14#include "../macros.hpp"
27hi_export_module(hikogui.telemetry :
log);
30hi_export
namespace hi {
inline namespace v1 {
45 static_assert(std::popcount(std::to_underlying(
Level)) == 1);
48 constexpr static 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>
65 _time_stamp(time_stamp_count::inplace_with_thread_id{}), _what(std::forward<Args>(
args)...)
75 auto const cpu_id = _time_stamp.cpu_id();
76 auto const thread_id = _time_stamp.thread_id();
79 if constexpr (to_bool(
Level & global_state_type::log_statistics)) {
84 "{} {}({}) {:5} {} ({}:{})",
97 return std::make_unique<log_message>(*
this);
101 time_stamp_count _time_stamp;
119 static_assert(std::popcount(std::to_underlying(
Level)) == 1);
121 auto const state =
global_state.load(std::memory_order::relaxed);
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)) {
154 auto const lock = std::scoped_lock(_mutex);
197 std::println(
stderr,
"{}", str);
202 static hi_inline std::jthread _log_thread;
208 static void log_thread_main(std::stop_token
stop_token)
noexcept;
212 static void subsystem_deinit()
noexcept;
221 _log_thread = std::jthread(log_thread_main);
226hi_inline
log log_global;
231 if (
hi::start_subsystem(global_state_type::log_is_running, log::subsystem_init, log::subsystem_deinit)) {
243hi_inline
void log::subsystem_deinit()
noexcept
246 if (_log_thread.joinable()) {
247 _log_thread.request_stop();
hi_inline void stop_subsystem(void(*deinit_function)())
Stop a sub-system.
Definition subsystem.hpp:203
hi_inline std::string get_thread_name(thread_id id) noexcept
Get the thread name of a thread id.
Definition thread_intf.hpp:62
hi_inline std::atomic< global_state_type > global_state
The global state of the hikogui framework.
Definition global_state.hpp:203
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:117
hi_inline bool global_state_disable(global_state_type subsystem, std::memory_order order=std::memory_order::seq_cst) noexcept
Disable a subsystem.
Definition global_state.hpp:249
global_state_type
The flag-type used for global state.
Definition global_state.hpp:32
hi_inline void set_log_level(global_state_type log_level) noexcept
Set the logging level.
Definition global_state.hpp:232
@ write
Allow write access to a file.
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
The HikoGUI namespace.
Definition recursive_iterator.hpp:15
hi_inline void atterminate(std::function< void()> f) noexcept
Register functions that need to be called on std::terminate().
Definition terminate.hpp:48
hi_inline std::chrono::time_zone const & cached_current_zone() noexcept
Cached current time zone.
Definition time_zone.hpp:39
hi_inline cpu_id_result cpu_id(uint32_t leaf_id, uint32_t index=0) noexcept
A generic x86 cpu-id instruction.
Definition cpu_id_x86.hpp:347
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:378
hi_force_inline void add(Args &&...args) noexcept
Log a message.
Definition log.hpp:117
static void stop_subsystem()
Stop the logger system.
Definition log.hpp:180
hi_no_inline void flush() noexcept
Flush all messages from the log_queue directly from this thread.
Definition log.hpp:147
static bool start_subsystem(global_state_type log_level=global_state_type::log_level_default)
Start the logger system.
Definition log.hpp:228
A string which may be used as a none-type template parameter.
Definition fixed_string.hpp:42