7#include "delayed_format.hpp"
8#include "format_check.hpp"
9#include "../container/module.hpp"
10#include "../time/module.hpp"
11#include "../utility/utility.hpp"
12#include "../concurrency/concurrency.hpp"
13#include "../console/console.hpp"
14#include "../macros.hpp"
28namespace hi {
inline namespace v1 {
43 static_assert(std::popcount(std::to_underlying(
Level)) == 1);
46 constexpr static char const *log_level_name =
47 Level == global_state_type::log_fatal ?
"fatal" :
48 Level == global_state_type::log_error ?
"error" :
49 Level == global_state_type::log_warning ?
"warning" :
50 Level == global_state_type::log_info ?
"info" :
51 Level == global_state_type::log_debug ?
"debug" :
52 Level == global_state_type::log_trace ?
"trace" :
53 Level == global_state_type::log_audit ?
"audit" :
54 Level == global_state_type::log_statistics ?
"stats" :
55 "<unknown log level>";
61 template<
typename...
Args>
63 _time_stamp(time_stamp_count::inplace_with_thread_id{}), _what(std::forward<Args>(args)...)
73 hilet
cpu_id = _time_stamp.cpu_id();
74 hilet thread_id = _time_stamp.thread_id();
77 if constexpr (to_bool(
Level & global_state_type::log_statistics)) {
82 "{} {}({}) {:5} {} ({}:{})\n",
95 return std::make_unique<log_message>(*
this);
99 time_stamp_count _time_stamp;
115 hi_force_inline
void add(
Args&&...args)
noexcept
117 static_assert(std::popcount(std::to_underlying(
Level)) == 1);
119 hilet state =
global_state.load(std::memory_order::relaxed);
132 std::forward<Args>(args)...);
134 if (to_bool(
Level & global_state_type::log_fatal)
or not to_bool(state & global_state_type::log_is_running)) {
152 hilet lock = std::scoped_lock(_mutex);
176 return hi::start_subsystem(global_state_type::log_is_running, log::subsystem_init, log::subsystem_deinit);
204 static inline std::jthread _log_thread;
210 inline static void log_thread_main(std::stop_token
stop_token)
noexcept;
214 inline static void subsystem_deinit()
noexcept;
223 _log_thread = std::jthread(log_thread_main);
228inline log log_global;
232inline void log::subsystem_deinit()
noexcept
235 if (_log_thread.joinable()) {
236 _log_thread.request_stop();
std::string get_thread_name(thread_id id) noexcept
Get the thread name of a thread id.
Definition thread_intf.hpp:63
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:116
std::atomic< global_state_type > global_state
The global state of the hikogui framework.
Definition global_state.hpp:201
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:247
global_state_type
The flag-type used for global state.
Definition global_state.hpp:30
void set_log_level(global_state_type log_level) noexcept
Set the logging level.
Definition global_state.hpp:230
void stop_subsystem(void(*deinit_function)())
Stop a sub-system.
Definition subsystem.hpp:202
@ write
Allow write access to a file.
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
hi_export void print(std::format_string< Args... > fmt, Args &&... args) noexcept
Output text to the console.
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
std::chrono::time_zone const & cached_current_zone() noexcept
Cached current time zone.
Definition time_zone.hpp:39
static bool start_subsystem(global_state_type log_level=global_state_type::log_level_default)
Start the logger system.
Definition log.hpp:173
hi_force_inline void add(Args &&...args) noexcept
Log a message.
Definition log.hpp:115
static void stop_subsystem()
Stop the logger system.
Definition log.hpp:182
hi_no_inline void flush() noexcept
Flush all messages from the log_queue directly from this thread.
Definition log.hpp:145
A string which may be used as a none-type template parameter.
Definition fixed_string.hpp:41