2#ifndef LOGIT_CPP_HEADER_LOGIT_CPP_LOGIT_LOGGERS_WINDOWSDEBUGLOGGER_HPP_INCLUDED
3#define LOGIT_CPP_HEADER_LOGIT_CPP_LOGIT_LOGGERS_WINDOWSDEBUGLOGGER_HPP_INCLUDED
41 explicit Config(
bool async_value =
false)
44 explicit Config(
bool async_value =
true)
64 m_executor.reset(new detail::SingleThreadExecutor());
65 m_executor->set_max_queue_size(m_config.queue_capacity);
66 m_executor->set_queue_policy(m_config.queue_policy);
73 bool use_dedicated_executor,
74 std::size_t queue_capacity,
78 use_dedicated_executor,
89 std::unique_ptr<detail::SingleThreadExecutor> old_executor;
92 if (
m_shutdown.load(std::memory_order_acquire))
return;
116 old_executor->shutdown();
132 if (
m_shutdown.load(std::memory_order_acquire)) {
143 m_executor->set_max_queue_size(queue_capacity);
155 void log(
const LogRecord& record,
const std::string& message)
override {
157 if (
m_shutdown.load(std::memory_order_acquire))
return;
238 if (
m_shutdown.exchange(
true, std::memory_order_acq_rel))
return;
257 bool use_dedicated_executor,
258 std::size_t queue_capacity,
270 if (message.empty()) {
271 OutputDebugStringW(L
"\n");
274 const int len =
static_cast<int>(message.size());
275 const int wlen = MultiByteToWideChar(CP_UTF8, 0, message.c_str(), len,
nullptr, 0);
278 wmsg.resize(
static_cast<size_t>(wlen));
279 MultiByteToWideChar(CP_UTF8, 0, message.c_str(), len, &wmsg[0], wlen);
281 OutputDebugStringW(wmsg.c_str());
283 OutputDebugStringA((message +
"\n").c_str());
286 std::cerr << message <<
'\n';
Defines the interface for loggers used in the logging system.
Optional buffered snapshot access returns empty results by default.
Outputs formatted log messages to the Windows debug console or stderr.
std::atomic< bool > m_shutdown
std::atomic< int64_t > m_last_log_ts
std::mutex m_lifecycle_mutex
std::unique_ptr< detail::SingleThreadExecutor > m_executor
void shutdown() override
Stops logger-owned asynchronous resources after draining pending messages.
WindowsDebugLogger()
Default constructor that uses default configuration.
WindowsDebugLogger(bool async, bool use_dedicated_executor, std::size_t queue_capacity, QueuePolicy queue_policy)
Constructor with asynchronous and dedicated executor options.
static void write_impl(const std::string &message)
void set_log_level(LogLevel level) override
Sets the minimal log level for this logger.
int64_t get_int_param(const LoggerParam ¶m) const override
Retrieves an integer parameter from the logger.
static Config make_config(bool async, bool use_dedicated_executor, std::size_t queue_capacity, QueuePolicy queue_policy)
WindowsDebugLogger(const Config &config)
Constructor with custom configuration.
LogLevel get_log_level() const override
Gets the minimal log level for this logger.
double get_float_param(const LoggerParam ¶m) const override
Retrieves a floating-point parameter from the logger.
void set_config(const Config &config)
Updates executor-related configuration at runtime.
std::string get_string_param(const LoggerParam ¶m) const override
Retrieves a string parameter from the logger.
bool set_queue_config(std::size_t queue_capacity, QueuePolicy queue_policy)
Updates queue_capacity and queue_policy at runtime without draining tasks.
void wait() override
Waits for all asynchronous tasks to complete.
std::atomic< int > m_log_level
void log(const LogRecord &record, const std::string &message) override
Logs a message to the Windows debug output or stderr.
Per-instance single-thread executor for isolated async logging.
void add_task(std::function< void()> task)
Enqueue a task for asynchronous execution.
void wait()
Block until the queue is empty or a shutdown is requested.
static TaskExecutor & get_instance()
Returns the global executor instance.
QueuePolicy
Queue overflow handling policy used by TaskExecutor and SingleThreadExecutor.
The primary namespace for the LogIt++ library.
@ LOG_LVL_TRACE
Trace level logging.
LoggerParam
Enumeration for different logger parameters that can be retrieved.
@ LastLogTimestamp
The timestamp of the last log.
Stores log metadata and content.
const int64_t timestamp_ms
Timestamp in milliseconds.
Configuration for the Windows debug logger.
bool use_dedicated_executor
Use a dedicated executor instead of the global TaskExecutor; native builds create one worker thread p...
Config(bool async_value=true)
Initializes configuration.
bool async
Flag indicating whether logging should be asynchronous.
QueuePolicy queue_policy
Overflow policy for the dedicated executor.
std::size_t queue_capacity
Maximum queue size for the dedicated executor (0 = unlimited).