19 static_assert(magic_enum::enum_count<Component>() <= 64);
20 static_assert(magic_enum::enum_count<Context>() <= 64);
30 f.store(
true, std::memory_order_relaxed);
32 f.store(
true, std::memory_order_relaxed);
50 std::cout <<
"[MayaFlux::Journal] Initialized\n";
67 std::cout <<
"[MayaFlux::Journal] Shutdown\n";
81 while (
m_push_lock.test_and_set(std::memory_order_acquire))
91 std::string_view message, std::source_location location)
131 std::cout <<
"[MayaFlux::Journal] WARNING: Dropped "
132 << dropped <<
" log messages (buffer full)\n";
138 m_sinks.push_back(std::move(sink));
155 auto comp_idx =
static_cast<size_t>(comp);
164 auto ctx_idx =
static_cast<size_t>(ctx);
173 uint64_t includes = 0;
174 for (
auto component : components) {
175 auto idx =
static_cast<size_t>(component);
177 includes |= uint64_t { 1 } << idx;
184 uint64_t includes = 0;
185 for (
auto context : contexts) {
186 auto idx =
static_cast<size_t>(context);
188 includes |= uint64_t { 1 } << idx;
199 auto comp_idx =
static_cast<size_t>(component);
205 if (component_includes != 0 && !(component_includes & (uint64_t { 1 } << comp_idx)))
208 auto ctx_idx =
static_cast<size_t>(context);
215 return context_includes == 0 || (context_includes & (uint64_t { 1 } << ctx_idx));
220 if (colors_enabled) {
268 if (sink->is_available()) {
272 std::cout <<
"[MayaFlux::Journal] WARNING: sink threw during write, skipping\n";
285 using namespace std::chrono_literals;
288 std::this_thread::sleep_for(10ms);
319 : m_impl(
std::make_unique<
Impl>())
333 m_impl->drain_ring_buffer();
337 std::string_view message, std::source_location location)
344 std::string_view message, std::source_location location)
346 m_impl->scribe_rt(
severity, component, context, message, location);
350 std::string_view message)
358 m_impl->add_sink(std::move(sink));
368 m_impl->set_min_severity(min_sev);
373 m_impl->set_component_filter(comp, enabled);
378 m_impl->set_context_filter(ctx, enabled);
383 m_impl->set_component_includes(components);
388 m_impl->set_context_includes(contexts);
void set_component_includes(const std::vector< Component > &components)
std::atomic_flag m_push_lock
std::array< std::atomic< bool >, magic_enum::enum_count< Component >()> m_component_filters
std::atomic< Severity > m_min_severity
std::atomic< bool > m_initialized
void set_component_filter(Component comp, bool enabled)
static constexpr size_t RT_RING_BUFFER_SIZE
bool should_log(Severity severity, Component component, Context context) const
std::array< std::atomic< bool >, magic_enum::enum_count< Context >()> m_context_filters
std::atomic< bool > m_shutdown_in_progress
std::atomic< bool > m_accepting_entries
void set_min_severity(Severity sev)
std::atomic< bool > m_worker_running
void write_to_sinks(const RealtimeEntry &entry)
Memory::MPSCQueue< RealtimeEntry, RT_RING_BUFFER_SIZE > m_rt_ring_buffer
static void write_to_console(const RealtimeEntry &entry)
Memory::LockFreeQueue< RealtimeEntry, RING_BUFFER_SIZE > m_ring_buffer
void scribe(const JournalEntry &entry)
void add_sink(std::unique_ptr< Sink > sink)
static constexpr size_t RING_BUFFER_SIZE
std::thread m_worker_thread
std::atomic< uint64_t > m_context_includes
void set_context_filter(Context ctx, bool enabled)
void drain_ring_buffer()
Drain all pending ring buffer entries to sinks or console.
void set_context_includes(const std::vector< Context > &contexts)
std::vector< std::unique_ptr< Sink > > m_sinks
std::atomic< uint64_t > m_dropped_messages
void scribe_rt(Severity severity, Component component, Context context, std::string_view message, std::source_location location)
std::atomic< uint64_t > m_component_includes
void scribe_simple(Component component, Context context, std::string_view message)
Log a simple message without source location information.
void add_sink(std::unique_ptr< Sink > sink)
Add a log sink for output.
void set_component_includes(const std::vector< Component > &components)
Restrict logging to these components; an empty list includes all.
void scribe_rt(Severity severity, Component component, Context context, std::string_view message, std::source_location location=std::source_location::current())
Log a message from a real-time context with the specified severity, component, and context.
void clear_sinks()
Remove all sinks.
void set_component_filter(Component comp, bool enabled)
Enable or disable logging for a specific component.
void flush()
Synchronously drain all pending ring buffer entries to sinks.
static void shutdown()
Shutdown the logging system.
void set_context_includes(const std::vector< Context > &contexts)
Restrict logging to these contexts; an empty list includes all.
static Archivist & instance()
Get the singleton instance of the Archivist.
void set_min_severity(Severity min_sev)
Set the minimum severity level for logging.
void scribe(Severity severity, Component component, Context context, std::string_view message, std::source_location location=std::source_location::current())
Log a message with the specified severity, component, and context.
std::unique_ptr< Impl > m_impl
void set_context_filter(Context ctx, bool enabled)
Enable or disable logging for a specific context.
Singleton class responsible for managing log entries.
Policy-driven unified circular buffer implementation.
static constexpr std::string_view Yellow
static constexpr std::string_view BrightBlue
static constexpr std::string_view White
static constexpr std::string_view Blue
static constexpr std::string_view Reset
static constexpr std::string_view Green
static constexpr std::string_view Cyan
static constexpr std::string_view BrightRed
static bool initialize_console_colors()
static constexpr std::string_view Magenta
Context
Execution contexts for log messages.
constexpr std::string_view enum_to_string(EnumType value) noexcept
Universal enum to string converter using magic_enum (original case)
std::source_location location
A log entry structure to encapsulate log message details.
char message[MAX_MESSAGE_LENGTH]
Lightweight entry for lock-free ring buffer.