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

Exports logs as OTLP JSON payloads via a user-provided callback. More...

#include <OtlpPayloadLogger.hpp>

Inheritance diagram for logit::OtlpPayloadLogger:
logit::ILogger

Classes

struct  Config
 

Public Member Functions

 OtlpPayloadLogger ()
 Constructs OTLP payload logger with default configuration.
 
 OtlpPayloadLogger (const Config &config)
 Constructs OTLP payload logger with custom configuration.
 
 ~OtlpPayloadLogger () override
 Stops worker and drains queue.
 
 OtlpPayloadLogger (const OtlpPayloadLogger &)=delete
 
OtlpPayloadLogger & operator= (const OtlpPayloadLogger &)=delete
 
void log (const LogRecord &record, const std::string &message) override
 Queues or exports a log message.
 
void wait () override
 Waits until queue is empty and worker is idle.
 
void shutdown () override
 Stops the OTLP worker after draining queued items.
 
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 minimal log level for this logger.
 
LogLevel get_log_level () const override
 Gets minimal log level for this logger.
 
uint64_t dropped_count () const
 Returns number of dropped records.
 
uint64_t failed_export_count () const
 Returns number of failed export attempts.
 
- 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.
 

Private Member Functions

void worker_loop ()
 Worker thread loop.
 
void stop ()
 Stops worker and drains remaining queue.
 
int64_t get_last_log_ts () const
 Returns last log timestamp.
 
int64_t get_time_since_last_log () const
 Returns elapsed time since last log.
 

Static Private Member Functions

static int64_t counter_to_int64 (uint64_t value)
 Converts unsigned counter value to int64_t with saturation.
 

Private Attributes

Config m_config
 
std::mutex m_mutex
 
std::condition_variable m_cv
 
std::condition_variable m_space_cv
 
std::deque< OtlpLogItem > m_queue
 
bool m_stopping = false
 
bool m_idle = true
 
std::thread m_worker
 
std::atomic< int > m_log_level = ATOMIC_VAR_INIT(static_cast<int>(LogLevel::LOG_LVL_TRACE))
 
std::atomic< int64_t > m_last_log_ts = ATOMIC_VAR_INIT(0)
 
std::atomic< uint64_t > m_dropped = ATOMIC_VAR_INIT(0)
 
std::atomic< uint64_t > m_failed_exports = ATOMIC_VAR_INIT(0)
 

Detailed Description

Exports logs as OTLP JSON payloads via a user-provided callback.

This backend serializes records to OTLP/HTTP JSON and passes each batch to a user-provided callback instead of sending HTTP itself.

Definition at line 37 of file OtlpPayloadLogger.hpp.

Constructor & Destructor Documentation

◆ OtlpPayloadLogger() [1/3]

logit::OtlpPayloadLogger::OtlpPayloadLogger ( )
inline

Constructs OTLP payload logger with default configuration.

Definition at line 51 of file OtlpPayloadLogger.hpp.

◆ OtlpPayloadLogger() [2/3]

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

Constructs OTLP payload logger with custom configuration.

Parameters
configExport configuration.

Definition at line 55 of file OtlpPayloadLogger.hpp.

◆ ~OtlpPayloadLogger()

logit::OtlpPayloadLogger::~OtlpPayloadLogger ( )
inlineoverride

Stops worker and drains queue.

Definition at line 63 of file OtlpPayloadLogger.hpp.

◆ OtlpPayloadLogger() [3/3]

logit::OtlpPayloadLogger::OtlpPayloadLogger ( const OtlpPayloadLogger & )
delete

Member Function Documentation

◆ counter_to_int64()

static int64_t logit::OtlpPayloadLogger::counter_to_int64 ( uint64_t value)
inlinestaticprivate

Converts unsigned counter value to int64_t with saturation.

Parameters
valueCounter value.
Returns
Counter value clamped to int64_t max.

Definition at line 337 of file OtlpPayloadLogger.hpp.

◆ dropped_count()

uint64_t logit::OtlpPayloadLogger::dropped_count ( ) const
inline

Returns number of dropped records.

Returns
Dropped record count.

Definition at line 215 of file OtlpPayloadLogger.hpp.

◆ failed_export_count()

uint64_t logit::OtlpPayloadLogger::failed_export_count ( ) const
inline

Returns number of failed export attempts.

Returns
Failed export count.

Definition at line 221 of file OtlpPayloadLogger.hpp.

◆ get_float_param()

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

Retrieves a floating-point parameter from the logger.

Parameters
paramParameter to retrieve.
Returns
Parameter value in seconds for time params, raw count for counter params, or 0.0 when unsupported.

Implements logit::ILogger.

Definition at line 185 of file OtlpPayloadLogger.hpp.

◆ get_int_param()

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

Retrieves an integer parameter from the logger.

Parameters
paramParameter to retrieve.
Returns
Parameter value, or 0 when unsupported.

Implements logit::ILogger.

Definition at line 170 of file OtlpPayloadLogger.hpp.

◆ get_last_log_ts()

int64_t logit::OtlpPayloadLogger::get_last_log_ts ( ) const
inlineprivate

Returns last log timestamp.

Returns
Last log timestamp in milliseconds.

Definition at line 319 of file OtlpPayloadLogger.hpp.

◆ get_log_level()

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

Gets minimal log level for this logger.

Returns
Current minimal log level.

Implements logit::ILogger.

Definition at line 209 of file OtlpPayloadLogger.hpp.

◆ get_string_param()

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

Retrieves a string parameter from the logger.

Parameters
paramParameter to retrieve.
Returns
Parameter value, or empty string when unsupported.

Implements logit::ILogger.

Definition at line 155 of file OtlpPayloadLogger.hpp.

◆ get_time_since_last_log()

int64_t logit::OtlpPayloadLogger::get_time_since_last_log ( ) const
inlineprivate

Returns elapsed time since last log.

Returns
Elapsed time in milliseconds.

Definition at line 325 of file OtlpPayloadLogger.hpp.

◆ log()

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

Queues or exports a log message.

Parameters
recordStructured log record.
messageFormatted log message used as OTLP body.

Implements logit::ILogger.

Definition at line 73 of file OtlpPayloadLogger.hpp.

◆ operator=()

OtlpPayloadLogger & logit::OtlpPayloadLogger::operator= ( const OtlpPayloadLogger & )
delete

◆ set_log_level()

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

Sets minimal log level for this logger.

Parameters
levelMinimum log level.

Implements logit::ILogger.

Definition at line 203 of file OtlpPayloadLogger.hpp.

◆ shutdown()

void logit::OtlpPayloadLogger::shutdown ( )
inlineoverridevirtual

Stops the OTLP worker after draining queued items.

Implements logit::ILogger.

Definition at line 148 of file OtlpPayloadLogger.hpp.

◆ stop()

void logit::OtlpPayloadLogger::stop ( )
inlineprivate

Stops worker and drains remaining queue.

Definition at line 300 of file OtlpPayloadLogger.hpp.

◆ wait()

void logit::OtlpPayloadLogger::wait ( )
inlineoverridevirtual

Waits until queue is empty and worker is idle.

Implements logit::ILogger.

Definition at line 136 of file OtlpPayloadLogger.hpp.

◆ worker_loop()

void logit::OtlpPayloadLogger::worker_loop ( )
inlineprivate

Worker thread loop.

Definition at line 243 of file OtlpPayloadLogger.hpp.

Member Data Documentation

◆ m_config

Config logit::OtlpPayloadLogger::m_config
private

Definition at line 226 of file OtlpPayloadLogger.hpp.

◆ m_cv

std::condition_variable logit::OtlpPayloadLogger::m_cv
private

Definition at line 229 of file OtlpPayloadLogger.hpp.

◆ m_dropped

std::atomic<uint64_t> logit::OtlpPayloadLogger::m_dropped = ATOMIC_VAR_INIT(0)
private

Definition at line 239 of file OtlpPayloadLogger.hpp.

◆ m_failed_exports

std::atomic<uint64_t> logit::OtlpPayloadLogger::m_failed_exports = ATOMIC_VAR_INIT(0)
private

Definition at line 240 of file OtlpPayloadLogger.hpp.

◆ m_idle

bool logit::OtlpPayloadLogger::m_idle = true
private

Definition at line 233 of file OtlpPayloadLogger.hpp.

◆ m_last_log_ts

std::atomic<int64_t> logit::OtlpPayloadLogger::m_last_log_ts = ATOMIC_VAR_INIT(0)
private

Definition at line 238 of file OtlpPayloadLogger.hpp.

◆ m_log_level

std::atomic<int> logit::OtlpPayloadLogger::m_log_level = ATOMIC_VAR_INIT(static_cast<int>(LogLevel::LOG_LVL_TRACE))
private

Definition at line 237 of file OtlpPayloadLogger.hpp.

◆ m_mutex

std::mutex logit::OtlpPayloadLogger::m_mutex
private

Definition at line 228 of file OtlpPayloadLogger.hpp.

◆ m_queue

std::deque<OtlpLogItem> logit::OtlpPayloadLogger::m_queue
private

Definition at line 231 of file OtlpPayloadLogger.hpp.

◆ m_space_cv

std::condition_variable logit::OtlpPayloadLogger::m_space_cv
private

Definition at line 230 of file OtlpPayloadLogger.hpp.

◆ m_stopping

bool logit::OtlpPayloadLogger::m_stopping = false
private

Definition at line 232 of file OtlpPayloadLogger.hpp.

◆ m_worker

std::thread logit::OtlpPayloadLogger::m_worker
private

Definition at line 235 of file OtlpPayloadLogger.hpp.


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