![]() |
LogIt++
Header-only, macro-first C++ logging library
|
Exports logs to an OTLP/HTTP endpoint using kurlyk. More...
#include <OtlpHttpLogger.hpp>
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 ¶m) const override |
| Retrieves a string parameter from the logger. | |
| int64_t | get_int_param (const LoggerParam ¶m) const override |
| Retrieves an integer parameter from the logger. | |
| double | get_float_param (const LoggerParam ¶m) 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) |
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.
|
inline |
Constructs OTLP HTTP logger with default configuration.
Definition at line 79 of file OtlpHttpLogger.hpp.
|
inlineexplicit |
Constructs OTLP HTTP logger with custom configuration.
| config | Export configuration. |
Definition at line 83 of file OtlpHttpLogger.hpp.
|
inlineoverride |
Stops worker and cancels pending HTTP requests.
Definition at line 111 of file OtlpHttpLogger.hpp.
|
delete |
|
inlinestaticprivate |
Converts unsigned counter value to int64_t with saturation.
| value | Counter value. |
Definition at line 485 of file OtlpHttpLogger.hpp.
|
inline |
Returns number of dropped records.
Definition at line 260 of file OtlpHttpLogger.hpp.
|
inline |
Returns number of failed export attempts.
Definition at line 266 of file OtlpHttpLogger.hpp.
|
inlineoverridevirtual |
Retrieves a floating-point parameter from the logger.
| param | Parameter to retrieve. |
Implements logit::ILogger.
Definition at line 230 of file OtlpHttpLogger.hpp.
|
inlineoverridevirtual |
Retrieves an integer parameter from the logger.
| param | Parameter to retrieve. |
Implements logit::ILogger.
Definition at line 215 of file OtlpHttpLogger.hpp.
|
inlineprivate |
Returns last log timestamp.
Definition at line 467 of file OtlpHttpLogger.hpp.
|
inlineoverridevirtual |
Gets minimal log level for this logger.
Implements logit::ILogger.
Definition at line 254 of file OtlpHttpLogger.hpp.
|
inlineoverridevirtual |
Retrieves a string parameter from the logger.
| param | Parameter to retrieve. |
Implements logit::ILogger.
Definition at line 200 of file OtlpHttpLogger.hpp.
|
inlineprivate |
Returns elapsed time since last log.
Definition at line 473 of file OtlpHttpLogger.hpp.
|
inlineoverridevirtual |
Queues or exports a log message.
| record | Structured log record. |
| message | Formatted log message used as OTLP body. |
Implements logit::ILogger.
Definition at line 121 of file OtlpHttpLogger.hpp.
|
delete |
|
inlineoverridevirtual |
Sets minimal log level for this logger.
| level | Minimum log level. |
Implements logit::ILogger.
Definition at line 248 of file OtlpHttpLogger.hpp.
|
inlineoverridevirtual |
Stops the OTLP worker after draining queued exports.
Implements logit::ILogger.
Definition at line 193 of file OtlpHttpLogger.hpp.
|
inlineprivate |
Stops worker and cancels pending requests.
Definition at line 427 of file OtlpHttpLogger.hpp.
|
inlineprivate |
Submits one batch asynchronously, splitting into payload chunks.
| batch | Batch to export. |
Definition at line 336 of file OtlpHttpLogger.hpp.
|
inlineoverridevirtual |
Waits until queued and in-flight exports finish.
Implements logit::ILogger.
Definition at line 181 of file OtlpHttpLogger.hpp.
|
inlineprivate |
Worker thread loop.
Definition at line 284 of file OtlpHttpLogger.hpp.
|
private |
HTTP client used for OTLP export.
Definition at line 272 of file OtlpHttpLogger.hpp.
|
private |
Export configuration.
Definition at line 271 of file OtlpHttpLogger.hpp.
|
private |
Definition at line 281 of file OtlpHttpLogger.hpp.
|
private |
Definition at line 280 of file OtlpHttpLogger.hpp.
|
mutableprivate |
Serializes log() with shutdown.
Definition at line 274 of file OtlpHttpLogger.hpp.
|
private |
Definition at line 279 of file OtlpHttpLogger.hpp.
|
private |
Definition at line 277 of file OtlpHttpLogger.hpp.
|
private |
Export worker thread.
Definition at line 275 of file OtlpHttpLogger.hpp.