2#ifndef LOGIT_CPP_HEADER_LOGIT_CPP_LOGIT_LOGGERS_PROMETHEUSPAYLOADLOGGER_HPP_INCLUDED
3#define LOGIT_CPP_HEADER_LOGIT_CPP_LOGIT_LOGGERS_PROMETHEUSPAYLOADLOGGER_HPP_INCLUDED
8#ifndef LOGIT_WITH_PROMETHEUS
9# error "PrometheusPayloadLogger requires LOGIT_WITH_PROMETHEUS=1. Enable LOGIT_WITH_PROMETHEUS in CMake."
38 std::function<void(std::vector<PrometheusMetricFamily>&)>
on_collect;
59 void log(
const LogRecord& record,
const std::string& message)
override {
91 std::vector<PrometheusMetricFamily> families;
120 return std::string();
Defines the interface for loggers used in the logging system.
Shared built-in metrics state and serialization for Prometheus loggers.
Prometheus text exposition format serialization helpers.
Optional buffered snapshot access returns empty results by default.
Tracks log-record counters and builds built-in Prometheus metric families.
void add_failed_export(uint64_t count=1)
Increment failed export/collect counter.
uint64_t dropped_count() const
Total dropped log records.
int64_t last_log_ts() const
Last log timestamp (ms).
uint64_t failed_export_count() const
Total failed export/collect attempts.
static int64_t counter_to_int64(uint64_t value)
Safely convert uint64_t counter to int64_t (clamping on overflow).
int64_t time_since_last_log_ms(int64_t now_ms) const
Milliseconds since last log record (0 if none).
void build_builtin_metrics(std::vector< PrometheusMetricFamily > &families, const PrometheusTextFormatConfig &config, const std::string &logger_name, int64_t now_ms=0) const
Append the six built-in metric families to families.
void on_log(int64_t timestamp_ms)
Update metrics when a log record is processed.
Exposes log metrics as Prometheus text exposition format via user-provided callback.
PrometheusPayloadLogger & operator=(const PrometheusPayloadLogger &)=delete
std::string collect_payload()
Collects current metrics and returns serialized Prometheus text payload.
PrometheusPayloadLogger(const Config &config)
Constructs Prometheus payload logger with custom configuration.
void wait() override
If emit_on_wait, collects metrics and invokes on_payload callback.
PrometheusPayloadLogger(const PrometheusPayloadLogger &)=delete
void log(const LogRecord &record, const std::string &message) override
Updates internal metric counters for a log message.
std::string get_string_param(const LoggerParam ¶m) const override
Retrieves a string parameter from the logger.
std::mutex m_collect_mutex
std::atomic< int > m_log_level
~PrometheusPayloadLogger() override=default
PrometheusPayloadLogger()
Constructs Prometheus payload logger with default configuration.
void set_log_level(LogLevel level) override
Sets minimal log level for this logger.
double get_float_param(const LoggerParam ¶m) const override
Retrieves a floating-point parameter from the logger.
LogLevel get_log_level() const override
Gets minimal log level for this logger.
int64_t get_int_param(const LoggerParam ¶m) const override
Retrieves an integer parameter from the logger.
void shutdown() override
Stops the logger (no worker thread to drain for payload logger).
PrometheusLoggerMetrics m_metrics
#define LOGIT_CURRENT_TIMESTAMP_MS()
Macro to get the current timestamp in milliseconds.
The primary namespace for the LogIt++ library.
@ LOG_LVL_TRACE
Trace level logging.
std::string build_prometheus_text_payload(const std::vector< PrometheusMetricFamily > &families, const PrometheusTextFormatConfig &config)
Builds a complete Prometheus text exposition format payload.
LoggerParam
Enumeration for different logger parameters that can be retrieved.
@ TimeSinceLastLog
The time elapsed since the last log in seconds.
@ LastLogTimestamp
The timestamp of the last log.
@ DroppedLogCount
Number of log records dropped by the backend.
@ FailedExportCount
Number of failed export attempts reported by the backend.
Stores log metadata and content.
const int64_t timestamp_ms
Timestamp in milliseconds.
std::function< void(std::string)> on_payload
std::function< void(std::vector< PrometheusMetricFamily > &)> on_collect
PrometheusTextFormatConfig format
Configuration for Prometheus text exposition format output.