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

Exports logs to an OTLP/HTTP endpoint using kurlyk. More...

#include <OtlpHttpLogger.hpp>

Inheritance diagram for logit::OtlpHttpLogger:
logit::ILogger

Classes

struct  Config
 

Public Member Functions

 OtlpHttpLogger ()
 Constructs OTLP HTTP logger with default configuration.
 
 OtlpHttpLogger (const Config &config)
 Constructs OTLP HTTP logger with custom configuration.
 
 ~OtlpHttpLogger () override
 Stops worker and cancels pending HTTP requests.
 
 OtlpHttpLogger (const OtlpHttpLogger &)=delete
 
OtlpHttpLogger & operator= (const OtlpHttpLogger &)=delete
 
void log (const LogRecord &record, const std::string &message) override
 Queues or exports a log message.
 
void wait () override
 Waits until queued and in-flight exports finish.
 
void shutdown () override
 Stops the OTLP worker after draining queued exports.
 
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 submit_batch_async (const std::vector< OtlpLogItem > &batch)
 Submits one batch asynchronously, splitting into payload chunks.
 
void stop ()
 Stops worker and cancels pending requests.
 
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
 Export configuration.
 
kurlyk::HttpClient m_client
 HTTP client used for OTLP export.
 
std::mutex m_lifecycle_mutex
 Serializes log() with shutdown.
 
std::thread m_worker
 Export worker thread.
 
std::shared_ptr< OtlpHttpLoggerState > m_state
 
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)
 

Detailed Description

Exports logs to an OTLP/HTTP endpoint using kurlyk.

This backend is an outbound OTLP exporter/client. It serializes records to OTLP/HTTP JSON and sends batches to an OpenTelemetry Collector-compatible endpoint.

Definition at line 57 of file OtlpHttpLogger.hpp.

Constructor & Destructor Documentation

◆ OtlpHttpLogger() [1/3]

logit::OtlpHttpLogger::OtlpHttpLogger ( )
inline

Constructs OTLP HTTP logger with default configuration.

Definition at line 79 of file OtlpHttpLogger.hpp.

◆ OtlpHttpLogger() [2/3]

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

Constructs OTLP HTTP logger with custom configuration.

Parameters
configExport configuration.

Definition at line 83 of file OtlpHttpLogger.hpp.

◆ ~OtlpHttpLogger()

logit::OtlpHttpLogger::~OtlpHttpLogger ( )
inlineoverride

Stops worker and cancels pending HTTP requests.

Definition at line 111 of file OtlpHttpLogger.hpp.

◆ OtlpHttpLogger() [3/3]

logit::OtlpHttpLogger::OtlpHttpLogger ( const OtlpHttpLogger & )
delete

Member Function Documentation

◆ counter_to_int64()

static int64_t logit::OtlpHttpLogger::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 485 of file OtlpHttpLogger.hpp.

◆ dropped_count()

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

Returns number of dropped records.

Returns
Dropped record count.

Definition at line 260 of file OtlpHttpLogger.hpp.

◆ failed_export_count()

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

Returns number of failed export attempts.

Returns
Failed export count.

Definition at line 266 of file OtlpHttpLogger.hpp.

◆ get_float_param()

double logit::OtlpHttpLogger::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 230 of file OtlpHttpLogger.hpp.

◆ get_int_param()

int64_t logit::OtlpHttpLogger::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 215 of file OtlpHttpLogger.hpp.

◆ get_last_log_ts()

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

Returns last log timestamp.

Returns
Last log timestamp in milliseconds.

Definition at line 467 of file OtlpHttpLogger.hpp.

◆ get_log_level()

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

Gets minimal log level for this logger.

Returns
Current minimal log level.

Implements logit::ILogger.

Definition at line 254 of file OtlpHttpLogger.hpp.

◆ get_string_param()

std::string logit::OtlpHttpLogger::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 200 of file OtlpHttpLogger.hpp.

◆ get_time_since_last_log()

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

Returns elapsed time since last log.

Returns
Elapsed time in milliseconds.

Definition at line 473 of file OtlpHttpLogger.hpp.

◆ log()

void logit::OtlpHttpLogger::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 121 of file OtlpHttpLogger.hpp.

◆ operator=()

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

◆ set_log_level()

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

Sets minimal log level for this logger.

Parameters
levelMinimum log level.

Implements logit::ILogger.

Definition at line 248 of file OtlpHttpLogger.hpp.

◆ shutdown()

void logit::OtlpHttpLogger::shutdown ( )
inlineoverridevirtual

Stops the OTLP worker after draining queued exports.

Implements logit::ILogger.

Definition at line 193 of file OtlpHttpLogger.hpp.

◆ stop()

void logit::OtlpHttpLogger::stop ( )
inlineprivate

Stops worker and cancels pending requests.

Definition at line 427 of file OtlpHttpLogger.hpp.

◆ submit_batch_async()

void logit::OtlpHttpLogger::submit_batch_async ( const std::vector< OtlpLogItem > & batch)
inlineprivate

Submits one batch asynchronously, splitting into payload chunks.

Parameters
batchBatch to export.

Definition at line 336 of file OtlpHttpLogger.hpp.

◆ wait()

void logit::OtlpHttpLogger::wait ( )
inlineoverridevirtual

Waits until queued and in-flight exports finish.

Implements logit::ILogger.

Definition at line 181 of file OtlpHttpLogger.hpp.

◆ worker_loop()

void logit::OtlpHttpLogger::worker_loop ( )
inlineprivate

Worker thread loop.

Definition at line 284 of file OtlpHttpLogger.hpp.

Member Data Documentation

◆ m_client

kurlyk::HttpClient logit::OtlpHttpLogger::m_client
private

HTTP client used for OTLP export.

Definition at line 272 of file OtlpHttpLogger.hpp.

◆ m_config

Config logit::OtlpHttpLogger::m_config
private

Export configuration.

Definition at line 271 of file OtlpHttpLogger.hpp.

◆ m_dropped

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

Definition at line 281 of file OtlpHttpLogger.hpp.

◆ m_last_log_ts

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

Definition at line 280 of file OtlpHttpLogger.hpp.

◆ m_lifecycle_mutex

std::mutex logit::OtlpHttpLogger::m_lifecycle_mutex
mutableprivate

Serializes log() with shutdown.

Definition at line 274 of file OtlpHttpLogger.hpp.

◆ m_log_level

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

Definition at line 279 of file OtlpHttpLogger.hpp.

◆ m_state

std::shared_ptr<OtlpHttpLoggerState> logit::OtlpHttpLogger::m_state
private

Definition at line 277 of file OtlpHttpLogger.hpp.

◆ m_worker

std::thread logit::OtlpHttpLogger::m_worker
private

Export worker thread.

Definition at line 275 of file OtlpHttpLogger.hpp.


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