Signed-off-by: faumaray <faumaray@gmail.com>
This commit is contained in:
faumaray committed 2026-06-25 02:16:11 +03:00
1 parent 96b8b19970
commit e4ddb0c8c4
2 files changed
+53 -64

No files matched your search

+33 -9
View File
@@ -1,5 +1,6 @@
#pragma once
#include "Void/Log/Field.hpp"
#include <Void/Async/MpscQueue.hpp>
#include <Void/Log/Entry.hpp>
#include <Void/Log/Level.hpp>
@@ -277,10 +278,10 @@ namespace Void::Logging
/// logger's lifetime). Buffered: auto-flush
/// threshold (adjustable).
/// @param policy Async overflow behaviour at capacity.
explicit Logger(Mode mode = Mode::Async,
std::size_t capacity = 512,
OverflowPolicy policy =
OverflowPolicy::Block) noexcept;
explicit Logger(
Mode mode = Mode::Async,
std::size_t capacity = 512,
OverflowPolicy policy = OverflowPolicy::Block) noexcept;
/// Stops and joins the worker thread (Async). Does NOT flush
/// remaining entries — see class-level note.
@@ -376,11 +377,34 @@ namespace Void::Logging
// =========================================================================
// Core (non-template) logging — canonical entry points
// =========================================================================
inline void log(
Level level, std::string_view message,
std::source_location location = std::source_location::current())
{
// Early level check outside the lock to avoid allocations on
// the hot path.
{
std::lock_guard lock(m_mutex);
if (level < m_level) {
return;
}
}
void log(Level level,
std::string_view message,
std::source_location location =
std::source_location::current());
const auto fields = current_fields();
Entry entry{
.kind = Kind::Message,
.level = level,
.message = std::string(message),
.timestamp = std::chrono::system_clock::now(),
.location = location,
.thread_id = std::this_thread::get_id(),
.scopes = s_scope_stack, // snapshot — s_scope_stack is
// thread-local
.fields = {fields.begin(), fields.end()},
};
submit(std::move(entry));
}
/// Route a fully-built Entry through this logger's level filter
/// and dispatch (queue / buffer / inline write). Meant for
@@ -524,7 +548,7 @@ namespace Void::Logging
OverflowPolicy m_policy;
mutable std::mutex m_mutex;
std::vector<Entry> m_buffer; // Buffered mode only
std::vector<Entry> m_buffer; // Buffered mode only
std::size_t m_buffer_capacity;
// ── Async machinery ──────────────────────────────────────────