LogIt++
Header-only, macro-first C++ logging library
Loading...
Searching...
No Matches
logit::WindowsDebugLogger Class Reference

Outputs formatted log messages to the Windows debug console or stderr. More...

#include <WindowsDebugLogger.hpp>

Inheritance diagram for logit::WindowsDebugLogger:
logit::ILogger

Classes

struct  Config
 Configuration for the Windows debug logger. More...
 

Public Member Functions

 WindowsDebugLogger ()
 Default constructor that uses default configuration.
 
 WindowsDebugLogger (const Config &config)
 Constructor with custom configuration.
 
 WindowsDebugLogger (bool async, bool use_dedicated_executor, std::size_t queue_capacity, QueuePolicy queue_policy)
 Constructor with asynchronous and dedicated executor options.
 
void set_config (const Config &config)
 Updates executor-related configuration at runtime.
 
bool set_queue_config (std::size_t queue_capacity, QueuePolicy queue_policy)
 Updates queue_capacity and queue_policy at runtime without draining tasks.
 
void log (const LogRecord &record, const std::string &message) override
 Logs a message to the Windows debug output or stderr.
 
std::string get_string_param (const LoggerParam &param) const override
 Retrieves a string parameter from the logger.
 
int64_t get_int_param (const LoggerParam &param) const override
 Retrieves an integer parameter from the logger.
 
double get_float_param (const LoggerParam &param) const override
 Retrieves a floating-point parameter from the logger.
 
void set_log_level (LogLevel level) override
 Sets the minimal log level for this logger.
 
LogLevel get_log_level () const override
 Gets the minimal log level for this logger.
 
void wait () override
 Waits for all asynchronous tasks to complete.
 
void shutdown () override
 Stops logger-owned asynchronous resources after draining pending messages.
 
- Public Member Functions inherited from logit::ILogger
virtual ~ILogger ()=default
 
virtual std::vector< std::string > get_buffered_strings () const
 Returns buffered formatted messages in chronological order.
 
virtual std::vector< BufferedLogEntry > get_buffered_entries () const
 Returns buffered structured entries in chronological order.
 
virtual std::vector< LogFileInfo > list_log_files () const
 Lists persisted log files owned by this backend.
 
virtual LogFileReadResult read_log_file (const std::string &path) const
 Reads one persisted log file owned by this backend.
 
virtual std::vector< LogFileReadResult > read_log_files (const std::vector< std::string > &paths) const
 Reads several persisted log files owned by this backend.
 
virtual LogClearResult clear_logs (const LogClearOptions &options=LogClearOptions())
 Clears logger-owned buffered or persisted records when supported.
 

Static Private Member Functions

static Config make_config (bool async, bool use_dedicated_executor, std::size_t queue_capacity, QueuePolicy queue_policy)
 
static void write_impl (const std::string &message)
 

Private Attributes

Config m_config
 
std::mutex m_lifecycle_mutex
 
std::atomic< int > m_log_level {static_cast<int>(LogLevel::LOG_LVL_TRACE)}
 
std::atomic< int64_t > m_last_log_ts {0}
 
std::atomic< bool > m_shutdown {false}
 
std::unique_ptr< detail::SingleThreadExecutor > m_executor
 

Detailed Description

Outputs formatted log messages to the Windows debug console or stderr.

On Windows this logger forwards messages to OutputDebugStringW(), making them visible in Visual Studio Output, DebugView (Sysinternals), WinDbg and other debuggers. On non-Windows platforms it falls back to std::cerr.

Key Features:

  • No-op when no debugger is attached (OutputDebugStringW cost is minimal).
  • Synchronous or asynchronous operation.
  • Thread-safe.

Definition at line 33 of file WindowsDebugLogger.hpp.

Constructor & Destructor Documentation

◆ WindowsDebugLogger() [1/3]

logit::WindowsDebugLogger::WindowsDebugLogger ( )
inline

Default constructor that uses default configuration.

Definition at line 58 of file WindowsDebugLogger.hpp.

◆ WindowsDebugLogger() [2/3]

logit::WindowsDebugLogger::WindowsDebugLogger ( const Config & config)
inlineexplicit

Constructor with custom configuration.

Parameters
configThe configuration for the logger.

Definition at line 62 of file WindowsDebugLogger.hpp.

◆ WindowsDebugLogger() [3/3]

logit::WindowsDebugLogger::WindowsDebugLogger ( bool async,
bool use_dedicated_executor,
std::size_t queue_capacity,
QueuePolicy queue_policy )
inline

Constructor with asynchronous and dedicated executor options.

Definition at line 71 of file WindowsDebugLogger.hpp.

Member Function Documentation

◆ get_float_param()

double logit::WindowsDebugLogger::get_float_param ( const LoggerParam & param) const
inlineoverridevirtual

Retrieves a floating-point parameter from the logger.

Parameters
paramThe parameter type to retrieve.
Returns
A double representing the requested parameter, or 0.0 if unsupported.

Implements logit::ILogger.

Definition at line 203 of file WindowsDebugLogger.hpp.

◆ get_int_param()

int64_t logit::WindowsDebugLogger::get_int_param ( const LoggerParam & param) const
inlineoverridevirtual

Retrieves an integer parameter from the logger.

Parameters
paramThe parameter type to retrieve.
Returns
An integer representing the requested parameter, or 0 if unsupported.

Implements logit::ILogger.

Definition at line 190 of file WindowsDebugLogger.hpp.

◆ get_log_level()

LogLevel logit::WindowsDebugLogger::get_log_level ( ) const
inlineoverridevirtual

Gets the minimal log level for this logger.

Implements logit::ILogger.

Definition at line 219 of file WindowsDebugLogger.hpp.

◆ get_string_param()

std::string logit::WindowsDebugLogger::get_string_param ( const LoggerParam & param) const
inlineoverridevirtual

Retrieves a string parameter from the logger.

Parameters
paramThe parameter type to retrieve.
Returns
A string representing the requested parameter.

Implements logit::ILogger.

Definition at line 177 of file WindowsDebugLogger.hpp.

◆ log()

void logit::WindowsDebugLogger::log ( const LogRecord & record,
const std::string & message )
inlineoverridevirtual

Logs a message to the Windows debug output or stderr.

If asynchronous logging is enabled, the message is added to the task queue; otherwise, it is logged directly.

Parameters
recordThe log record containing log information.
messageThe formatted log message.

Implements logit::ILogger.

Definition at line 155 of file WindowsDebugLogger.hpp.

◆ make_config()

static Config logit::WindowsDebugLogger::make_config ( bool async,
bool use_dedicated_executor,
std::size_t queue_capacity,
QueuePolicy queue_policy )
inlinestaticprivate

Definition at line 255 of file WindowsDebugLogger.hpp.

◆ set_config()

void logit::WindowsDebugLogger::set_config ( const Config & config)
inline

Updates executor-related configuration at runtime.

This call is blocking. If asynchronous logging is currently enabled, it waits until already accepted tasks are drained before changing async mode or executor ownership. Only async, use_dedicated_executor, queue_capacity, and queue_policy are applied. Other fields in Config are ignored. For hot queue tuning without switching executor mode, use set_queue_config().

Definition at line 88 of file WindowsDebugLogger.hpp.

◆ set_log_level()

void logit::WindowsDebugLogger::set_log_level ( LogLevel level)
inlineoverridevirtual

Sets the minimal log level for this logger.

Implements logit::ILogger.

Definition at line 214 of file WindowsDebugLogger.hpp.

◆ set_queue_config()

bool logit::WindowsDebugLogger::set_queue_config ( std::size_t queue_capacity,
QueuePolicy queue_policy )
inline

Updates queue_capacity and queue_policy at runtime without draining tasks.

Parameters
queue_capacityNew maximum queue size (0 = unlimited).
queue_policyOverflow policy for the executor queue.
Returns
true if a dedicated executor was present and updated; false if the logger is shut down or uses the global executor.

Unlike set_config(), this method never blocks on task drain and never changes async mode or executor ownership. If no dedicated executor exists, only the stored config fields are updated for future reference.

Definition at line 128 of file WindowsDebugLogger.hpp.

◆ shutdown()

void logit::WindowsDebugLogger::shutdown ( )
inlineoverridevirtual

Stops logger-owned asynchronous resources after draining pending messages.

Implements logit::ILogger.

Definition at line 235 of file WindowsDebugLogger.hpp.

◆ wait()

void logit::WindowsDebugLogger::wait ( )
inlineoverridevirtual

Waits for all asynchronous tasks to complete.

Implements logit::ILogger.

Definition at line 224 of file WindowsDebugLogger.hpp.

◆ write_impl()

static void logit::WindowsDebugLogger::write_impl ( const std::string & message)
inlinestaticprivate

Definition at line 267 of file WindowsDebugLogger.hpp.

Member Data Documentation

◆ m_config

Config logit::WindowsDebugLogger::m_config
private

Definition at line 248 of file WindowsDebugLogger.hpp.

◆ m_executor

std::unique_ptr<detail::SingleThreadExecutor> logit::WindowsDebugLogger::m_executor
private

Definition at line 253 of file WindowsDebugLogger.hpp.

◆ m_last_log_ts

std::atomic<int64_t> logit::WindowsDebugLogger::m_last_log_ts {0}
private

Definition at line 251 of file WindowsDebugLogger.hpp.

◆ m_lifecycle_mutex

std::mutex logit::WindowsDebugLogger::m_lifecycle_mutex
private

Definition at line 249 of file WindowsDebugLogger.hpp.

◆ m_log_level

std::atomic<int> logit::WindowsDebugLogger::m_log_level {static_cast<int>(LogLevel::LOG_LVL_TRACE)}
private

Definition at line 250 of file WindowsDebugLogger.hpp.

◆ m_shutdown

std::atomic<bool> logit::WindowsDebugLogger::m_shutdown {false}
private

Definition at line 252 of file WindowsDebugLogger.hpp.


The documentation for this class was generated from the following file: