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

The primary namespace for the LogIt++ library. More...

Namespaces

namespace  detail
 

Classes

struct  BufferedLogEntry
 Structured representation of a buffered log snapshot entry. More...
 
class  ConsoleLogger
 Outputs log messages to the console with optional ANSI color support. More...
 
struct  ConsoleStreamRoute
 Maps a log-level range to a target output stream. More...
 
class  CrashPosixLogger
 Stub implementation on non-POSIX platforms. More...
 
class  CrashWindowsLogger
 \class CrashWindowsLogger \brief Stub implementation on non-Windows platforms. More...
 
class  EventLogLogger
 Stub logger when Windows Event Log is unavailable. More...
 
class  FileLogger
 Logs messages to files with date-based rotation and automatic deletion of old logs. More...
 
struct  FormatInstruction
 Structure to store log formatting instructions. More...
 
interface  ILogFormatter
 Interface for formatting log records. More...
 
interface  ILogger
 Optional buffered snapshot access returns empty results by default. More...
 
class  ILogReader
 Optional interface for backends that expose stored records. More...
 
class  ILogSubscriber
 Optional interface for backends that can notify callers when a record is successfully written. More...
 
struct  LogClearOptions
 Selects which data categories a logger cleanup should remove. More...
 
struct  LogClearResult
 Result returned by logger cleanup operations. More...
 
struct  LogFileInfo
 Metadata for a persisted log file owned by a logger backend. More...
 
struct  LogFileReadResult
 Result of reading a persisted log file from a file-based backend. More...
 
class  Logger
 Singleton class managing multiple loggers and formatters. More...
 
struct  LogRecord
 Stores log metadata and content. More...
 
struct  LogRecordSnapshot
 Common owning snapshot of a stored log record. More...
 
class  LogStream
 A stream-based logger that collects log messages using the << operator. More...
 
class  MdbxLogger
 Stores formatted logs in MDBX tables with optional async batching. More...
 
class  MemoryLogger
 Stores the latest formatted log messages in memory. More...
 
class  OtlpHttpLogger
 Exports logs to an OTLP/HTTP endpoint using kurlyk. More...
 
struct  OtlpHttpLoggerState
 
struct  OtlpJsonFormatConfig
 Serialization settings for OTLP JSON payload construction. More...
 
struct  OtlpLogItem
 Owns one formatted log message and its structured metadata. More...
 
class  OtlpPayloadLogger
 Exports logs as OTLP JSON payloads via a user-provided callback. More...
 
struct  OtlpRecordSnapshot
 Owns LogRecord fields required after original logging call returns. More...
 
struct  PathComponents
 Structure to hold the root and components of a path. More...
 
class  PatternCompiler
 Compiler for log formatting patterns. More...
 
class  PrometheusHttpServerLogger
 Serves Prometheus metrics via an embedded HTTP server. More...
 
struct  PrometheusLabel
 A single Prometheus label key-value pair. More...
 
class  PrometheusLoggerMetrics
 Tracks log-record counters and builds built-in Prometheus metric families. More...
 
struct  PrometheusMetricFamily
 A group of related samples sharing a name, help, and type. More...
 
class  PrometheusPayloadLogger
 Exposes log metrics as Prometheus text exposition format via user-provided callback. More...
 
class  PrometheusRegistry
 Stores custom gauge and counter callbacks for Prometheus collection. More...
 
struct  PrometheusSample
 A single metric sample with optional labels and timestamp. More...
 
struct  PrometheusTextFormatConfig
 Configuration for Prometheus text exposition format output. More...
 
class  SimpleLogFormatter
 A simple log formatter that formats log messages based on a user-defined pattern. More...
 
class  SyslogLogger
 Stub logger when syslog is unavailable. More...
 
class  UniqueFileLogger
 Writes each log message to a unique file with automatic cleanup. More...
 
struct  VariableValue
 Structure for storing values of various types, including enumerations. More...
 
class  WindowsDebugLogger
 Outputs formatted log messages to the Windows debug console or stderr. More...
 

Typedefs

using LoggerMutex = std::mutex
 
using LoggerReadLock = std::unique_lock<LoggerMutex>
 
using LoggerWriteLock = std::unique_lock<LoggerMutex>
 
using QueuePolicy = detail::QueuePolicy
 Public queue overflow handling policy.
 
using CrashLogger = CrashPosixLogger
 
using SystemLogger = SyslogLogger
 POSIX system logger alias.
 
using crev_it_t = std::string::const_reverse_iterator
 

Enumerations

enum class  LogLevel {
  LOG_LVL_TRACE , LOG_LVL_DEBUG , LOG_LVL_INFO , LOG_LVL_WARN ,
  LOG_LVL_ERROR , LOG_LVL_FATAL
}
 Logging levels. More...
 
enum class  TextColor {
  Black , DarkRed , DarkGreen , DarkYellow ,
  DarkBlue , DarkMagenta , DarkCyan , LightGray ,
  DarkGray , Red , Green , Yellow ,
  Blue , Magenta , Cyan , White
}
 Text colors for console output. More...
 
enum class  LoggerParam {
  LastFileName , LastFilePath , LastLogTimestamp , TimeSinceLastLog ,
  DroppedLogCount , FailedExportCount
}
 Enumeration for different logger parameters that can be retrieved. More...
 
enum class  CompressType { NONE , GZIP , ZSTD , EXTERNAL_CMD }
 Supported compression algorithms for rotated files. More...
 
enum class  RotationNaming { Sequence , Timestamp , TimestampMs }
 Naming policy for rotated log files. More...
 
enum class  ConsoleStreamKind { Cout , Cerr , Custom }
 Identifies a target output stream for ConsoleLogger routes. More...
 
enum class  LogClearStatus { Cleared , Unsupported , Failed }
 Backend cleanup status. More...
 
enum class  LogReadOrder { Ascending , Descending }
 Ordering for query results returned by ILogReader. More...
 
enum class  MdbxPayloadCompression { None = 0 , Gzip = 1 , Zstd = 2 }
 Compression algorithm used for payload rows. More...
 
enum class  OtlpCompression { None , Gzip , Zstd }
 Compression algorithm used for an OTLP/HTTP request payload. More...
 
enum class  PrometheusMetricType { Counter , Gauge , Untyped }
 Prometheus metric type identifiers. More...
 

Functions

const char * to_c_str (LogLevel level, int mode=0)
 Convert LogLevel to a C-style string representation.
 
std::string to_string (LogLevel level, int mode=0)
 Convert LogLevel to a std::string representation.
 
const char * to_c_str (TextColor color)
 Convert TextColor to a C-style string (ANSI escape codes).
 
std::string to_string (TextColor color)
 Convert TextColor to a std::string (ANSI escape codes).
 
std::string get_log_level_color (LogLevel log_level)
 Get the ANSI color code associated with a log level.
 
std::string otlp_json_escape (const std::string &value)
 Escapes a string for JSON output.
 
int otlp_severity_number (LogLevel level)
 Maps LogIt++ levels to OpenTelemetry severity numbers.
 
void otlp_write_comma_if_needed (std::ostringstream &os, bool &first)
 Writes a comma before the next JSON value when needed.
 
void otlp_write_string_attr (std::ostringstream &os, const std::string &key, const std::string &value)
 Writes a string OTLP attribute.
 
void otlp_write_int_attr (std::ostringstream &os, const std::string &key, int64_t value)
 Writes an int OTLP attribute.
 
void otlp_write_bool_attr (std::ostringstream &os, const std::string &key, bool value)
 Writes a bool OTLP attribute.
 
void otlp_write_double_attr (std::ostringstream &os, const std::string &key, double value)
 Writes a double OTLP attribute.
 
void otlp_write_uint_attr (std::ostringstream &os, const std::string &key, uint64_t value)
 Writes a uint64 OTLP attribute.
 
std::string sanitize_otlp_key (const std::string &name)
 Sanitizes an attribute key for OTLP.
 
void otlp_write_log_record_json (std::ostringstream &os, const OtlpLogItem &item, const OtlpJsonFormatConfig &config)
 Writes one OTLP JSON log record.
 
std::string build_otlp_logs_json_payload (const std::vector< OtlpLogItem > &batch, const OtlpJsonFormatConfig &config)
 Builds an OTLP ExportLogsServiceRequest JSON payload.
 
std::vector< std::string > build_otlp_logs_json_payload_chunks (const std::vector< OtlpLogItem > &batch, const OtlpJsonFormatConfig &format, std::size_t max_payload_bytes)
 Builds OTLP JSON payload chunks from a batch, splitting when a chunk would exceed max_payload_bytes.
 
std::string otlp_thread_id_to_string (const std::thread::id &id)
 Converts thread id to a portable string representation.
 
OtlpRecordSnapshot make_otlp_record_snapshot (const LogRecord &record)
 Creates an owned snapshot from a LogRecord.
 
PrometheusLabel make_prometheus_label (const std::string &name, const std::string &value)
 Create a single label pair.
 
PrometheusSample make_prometheus_sample (const std::string &name, double value, std::vector< PrometheusLabel > labels={}, int64_t timestamp_ms=0)
 Create a sample for a Prometheus metric family.
 
PrometheusMetricFamily make_prometheus_counter (const std::string &name, const std::string &help, double value)
 Create a Counter metric family with one unlabeled sample.
 
PrometheusMetricFamily make_prometheus_counter (const std::string &name, const std::string &help, double value, std::vector< PrometheusLabel > labels)
 Create a Counter metric family with one labeled sample.
 
PrometheusMetricFamily make_prometheus_gauge (const std::string &name, const std::string &help, double value)
 Create a Gauge metric family with one unlabeled sample.
 
PrometheusMetricFamily make_prometheus_gauge (const std::string &name, const std::string &help, double value, std::vector< PrometheusLabel > labels)
 Create a Gauge metric family with one labeled sample.
 
PrometheusMetricFamily make_prometheus_untyped (const std::string &name, const std::string &help, double value)
 Create an Untyped metric family with one unlabeled sample.
 
PrometheusMetricFamily make_prometheus_untyped (const std::string &name, const std::string &help, double value, std::vector< PrometheusLabel > labels)
 Create an Untyped metric family with one labeled sample.
 
void add_prometheus_counter (std::vector< PrometheusMetricFamily > &families, const std::string &name, const std::string &help, double value, std::vector< PrometheusLabel > labels={})
 Append a Counter metric family to the families vector (convenience for on_collect).
 
void add_prometheus_gauge (std::vector< PrometheusMetricFamily > &families, const std::string &name, const std::string &help, double value, std::vector< PrometheusLabel > labels={})
 Append a Gauge metric family to the families vector (convenience for on_collect).
 
void add_prometheus_untyped (std::vector< PrometheusMetricFamily > &families, const std::string &name, const std::string &help, double value, std::vector< PrometheusLabel > labels={})
 Append an Untyped metric family to the families vector (convenience for on_collect).
 
std::string prometheus_escape_help (const std::string &value)
 Escapes help string for Prometheus text format.
 
std::string prometheus_escape_label_value (const std::string &value)
 Escapes label value for Prometheus text format.
 
std::string prometheus_sanitize_metric_name (const std::string &name)
 Sanitizes a metric name to match Prometheus naming rules.
 
std::string prometheus_sanitize_label_name (const std::string &name)
 Sanitizes a label name to match Prometheus naming rules.
 
void prometheus_format_value (std::ostringstream &os, double value)
 Formats a Prometheus sample value according to text format rules.
 
void prometheus_write_metric_family (std::ostringstream &os, const PrometheusMetricFamily &family, const PrometheusTextFormatConfig &config)
 Writes one PrometheusMetricFamily to an output stream.
 
std::string build_prometheus_text_payload (const std::vector< PrometheusMetricFamily > &families, const PrometheusTextFormatConfig &config)
 Builds a complete Prometheus text exposition format payload.
 
std::vector< VariableValue > args_to_array (std::vector< std::string >::const_iterator)
 Base case of recursion for argument conversion — when there are no more arguments.
 
template<typename T , typename... Ts>
std::vector< VariableValue > args_to_array (std::vector< std::string >::const_iterator name_iter, const T &first_arg, const Ts &... args)
 Recursive function to convert arguments into an array of tuples (name, value).
 
bool is_closing_template (crev_it_t left_it, crev_it_t right_it)
 Checks if the '>' character is the closing of a template argument list.
 
std::vector< std::string > split_arguments (const std::string &all_names)
 Splits a string of argument names into individual names, ignoring nested templates, parentheses, and quotes.
 
std::string format (const char *fmt,...)
 Formats a string according to the specified format.
 
std::string get_exec_dir ()
 Retrieves the directory of the executable file.
 
std::vector< std::string > get_list_files (const std::string &path)
 Recursively retrieves a list of all files in a directory.
 
std::string get_file_name (const std::string &file_path)
 Extracts the file name from a full file path.
 
PathComponents split_path (const std::string &path)
 Splits a path into its root and components.
 
std::string make_relative (const std::string &file_path, const std::string &base_path)
 Computes the relative path from base_path to file_path.
 
bool is_file (const std::string &path)
 Checks if a path represents a file (by checking for an extension).
 
void create_directories (const std::string &path)
 Creates directories recursively for the given path.
 
template<typename EnumType >
std::string enum_to_string (EnumType value)
 Helper function to convert an enumeration to a string.
 
template<>
std::string enum_to_string (COLORS value)
 

Detailed Description

The primary namespace for the LogIt++ library.

\file CrashWindowsLogger.hpp \brief Windows crash logger persisting the last messages to a file handle.

\file CrashLogger.hpp \brief Platform-specific crash logger alias.

Typedef Documentation

◆ CrashLogger

Definition at line 16 of file CrashLogger.hpp.

◆ crev_it_t

using logit::crev_it_t = std::string::const_reverse_iterator

Definition at line 38 of file argument_utils.hpp.

◆ LoggerMutex

using logit::LoggerMutex = std::mutex

Definition at line 33 of file Logger.hpp.

◆ LoggerReadLock

using logit::LoggerReadLock = std::unique_lock<LoggerMutex>

Definition at line 34 of file Logger.hpp.

◆ LoggerWriteLock

using logit::LoggerWriteLock = std::unique_lock<LoggerMutex>

Definition at line 35 of file Logger.hpp.

◆ QueuePolicy

Public queue overflow handling policy.

Definition at line 20 of file loggers.hpp.

◆ SystemLogger

POSIX system logger alias.

Definition at line 17 of file SystemLogger.hpp.

Enumeration Type Documentation

◆ CompressType

enum class logit::CompressType
strong

Supported compression algorithms for rotated files.

Enumerator
NONE 

Do not compress rotated files.

GZIP 

Compress using gzip (zlib).

ZSTD 

Compress using zstd.

EXTERNAL_CMD 

Use an external command for compression.

Definition at line 58 of file enums.hpp.

◆ ConsoleStreamKind

enum class logit::ConsoleStreamKind
strong

Identifies a target output stream for ConsoleLogger routes.

Enumerator
Cout 

Routes records to std::cout.

Cerr 

Routes records to std::cerr.

Custom 

Routes records to a caller-provided std::ostream pointer.

Definition at line 14 of file ConsoleStreamRoute.hpp.

◆ LogClearStatus

enum class logit::LogClearStatus
strong

Backend cleanup status.

Enumerator
Cleared 
Unsupported 
Failed 

Definition at line 27 of file ILogger.hpp.

◆ LoggerParam

enum class logit::LoggerParam
strong

Enumeration for different logger parameters that can be retrieved.

Enumerator
LastFileName 

The name of the last file written to.

LastFilePath 

The full path of the last file written to.

LastLogTimestamp 

The timestamp of the last log.

TimeSinceLastLog 

The time elapsed since the last log in seconds.

DroppedLogCount 

Number of log records dropped by the backend.

FailedExportCount 

Number of failed export attempts reported by the backend.

Definition at line 47 of file enums.hpp.

◆ LogLevel

enum class logit::LogLevel
strong

Logging levels.

Enumerator
LOG_LVL_TRACE 

Trace level logging.

LOG_LVL_DEBUG 

Debug level logging.

LOG_LVL_INFO 

Information level logging.

LOG_LVL_WARN 

Warning level logging.

LOG_LVL_ERROR 

Error level logging.

LOG_LVL_FATAL 

Fatal level logging.

Definition at line 15 of file enums.hpp.

◆ LogReadOrder

enum class logit::LogReadOrder
strong

Ordering for query results returned by ILogReader.

Enumerator
Ascending 

Oldest first.

Descending 

Newest first.

Definition at line 38 of file ILogReader.hpp.

◆ MdbxPayloadCompression

enum class logit::MdbxPayloadCompression
strong

Compression algorithm used for payload rows.

Enumerator
None 

Store payload bytes as-is.

Gzip 

Store gzip-compressed payload bytes.

Zstd 

Store zstd-compressed payload bytes.

Definition at line 23 of file MdbxLogger.hpp.

◆ OtlpCompression

enum class logit::OtlpCompression
strong

Compression algorithm used for an OTLP/HTTP request payload.

Enumerator
None 
Gzip 
Zstd 

Definition at line 12 of file OtlpCompressionType.hpp.

◆ PrometheusMetricType

enum class logit::PrometheusMetricType
strong

Prometheus metric type identifiers.

Enumerator
Counter 
Gauge 
Untyped 

Definition at line 16 of file PrometheusTextFormatConfig.hpp.

◆ RotationNaming

enum class logit::RotationNaming
strong

Naming policy for rotated log files.

Enumerator
Sequence 

Append a numeric sequence: YYYY-MM-DD.001.log.

Timestamp 

Append HHMMSS timestamp: YYYY-MM-DD_HHMMSS.log.

TimestampMs 

Append HHMMSSmmm timestamp: YYYY-MM-DD_HHMMSSmmm.log.

Definition at line 67 of file enums.hpp.

◆ TextColor

enum class logit::TextColor
strong

Text colors for console output.

Enumerator
Black 
DarkRed 
DarkGreen 
DarkYellow 
DarkBlue 
DarkMagenta 
DarkCyan 
LightGray 
DarkGray 
Red 
Green 
Yellow 
Blue 
Magenta 
Cyan 
White 

Definition at line 26 of file enums.hpp.

Function Documentation

◆ add_prometheus_counter()

void logit::add_prometheus_counter ( std::vector< PrometheusMetricFamily > & families,
const std::string & name,
const std::string & help,
double value,
std::vector< PrometheusLabel > labels = {} )
inline

Append a Counter metric family to the families vector (convenience for on_collect).

Definition at line 122 of file PrometheusMetricBuilders.hpp.

◆ add_prometheus_gauge()

void logit::add_prometheus_gauge ( std::vector< PrometheusMetricFamily > & families,
const std::string & name,
const std::string & help,
double value,
std::vector< PrometheusLabel > labels = {} )
inline

Append a Gauge metric family to the families vector (convenience for on_collect).

Definition at line 132 of file PrometheusMetricBuilders.hpp.

◆ add_prometheus_untyped()

void logit::add_prometheus_untyped ( std::vector< PrometheusMetricFamily > & families,
const std::string & name,
const std::string & help,
double value,
std::vector< PrometheusLabel > labels = {} )
inline

Append an Untyped metric family to the families vector (convenience for on_collect).

Definition at line 142 of file PrometheusMetricBuilders.hpp.

◆ args_to_array() [1/2]

template<typename T , typename... Ts>
std::vector< VariableValue > logit::args_to_array ( std::vector< std::string >::const_iterator name_iter,
const T & first_arg,
const Ts &... args )

Recursive function to convert arguments into an array of tuples (name, value).

Template Parameters
TType of the first argument.
TsTypes of the remaining arguments.
Parameters
name_iterIterator for the argument name list.
first_argThe first argument.
argsThe remaining arguments.
Returns
A vector of tuples containing argument names and values.

Definition at line 27 of file argument_utils.hpp.

◆ args_to_array() [2/2]

std::vector< VariableValue > logit::args_to_array ( std::vector< std::string >::const_iterator )
inline

Base case of recursion for argument conversion — when there are no more arguments.

Returns
An empty vector, as there are no more arguments to process.

Definition at line 15 of file argument_utils.hpp.

◆ build_otlp_logs_json_payload()

std::string logit::build_otlp_logs_json_payload ( const std::vector< OtlpLogItem > & batch,
const OtlpJsonFormatConfig & config )
inline

Builds an OTLP ExportLogsServiceRequest JSON payload.

Parameters
batchLog batch to serialize.
configExport configuration.
Returns
OTLP/HTTP JSON payload.

Definition at line 299 of file OtlpJsonSerializer.hpp.

◆ build_otlp_logs_json_payload_chunks()

std::vector< std::string > logit::build_otlp_logs_json_payload_chunks ( const std::vector< OtlpLogItem > & batch,
const OtlpJsonFormatConfig & format,
std::size_t max_payload_bytes )
inline

Builds OTLP JSON payload chunks from a batch, splitting when a chunk would exceed max_payload_bytes.

Parameters
batchLog items to serialize.
formatSerialization configuration.
max_payload_bytesMaximum serialized size per chunk (0 = no splitting).
Returns
Vector of JSON payload strings, one per chunk.

Definition at line 20 of file OtlpPayloadSplitter.hpp.

◆ build_prometheus_text_payload()

std::string logit::build_prometheus_text_payload ( const std::vector< PrometheusMetricFamily > & families,
const PrometheusTextFormatConfig & config )
inline

Builds a complete Prometheus text exposition format payload.

Parameters
familiesMetric families to serialize.
configFormat configuration.
Returns
Complete text exposition payload string.

Definition at line 200 of file PrometheusTextSerializer.hpp.

◆ create_directories()

void logit::create_directories ( const std::string & path)
inline

Creates directories recursively for the given path.

Parameters
pathThe directory path to create.
Exceptions
std::runtime_errorif the directories cannot be created.

Definition at line 394 of file path_utils.hpp.

◆ enum_to_string() [1/2]

template<>
std::string logit::enum_to_string ( COLORS value)

Definition at line 46 of file example_logit_basic.cpp.

◆ enum_to_string() [2/2]

template<typename EnumType >
std::string logit::enum_to_string ( EnumType value)

Helper function to convert an enumeration to a string.

Template Parameters
EnumTypeThe enumeration type.
Parameters
valueThe enumeration value.
Returns
String representation of the enumeration.

Definition at line 34 of file VariableValue.hpp.

◆ format()

std::string logit::format ( const char * fmt,
... )
inline

Formats a string according to the specified format.

This function uses a vsnprintf-based implementation.

Parameters
fmtThe format string (similar to printf format).
...A variable number of arguments matching the format string.
See also
https://habr.com/ru/articles/318962/
Returns
A formatted std::string.

Definition at line 22 of file format.hpp.

◆ get_exec_dir()

std::string logit::get_exec_dir ( )
inline

Retrieves the directory of the executable file.

Returns
A string containing the directory path of the executable.

Definition at line 72 of file path_utils.hpp.

◆ get_file_name()

std::string logit::get_file_name ( const std::string & file_path)
inline

Extracts the file name from a full file path.

Parameters
file_pathThe full file path as a string.
Returns
The extracted file name, or the full string if no directory separator is found.

Definition at line 226 of file path_utils.hpp.

◆ get_list_files()

std::vector< std::string > logit::get_list_files ( const std::string & path)
inline

Recursively retrieves a list of all files in a directory.

Parameters
pathThe directory path to search (UTF-8 encoded).
Returns
A vector of strings (UTF-8) containing the full paths of all files found.

Definition at line 141 of file path_utils.hpp.

◆ get_log_level_color()

std::string logit::get_log_level_color ( LogLevel log_level)
inline

Get the ANSI color code associated with a log level.

Parameters
log_levelThe log level.
Returns
ANSI escape code string representing the color for the log level.

Definition at line 150 of file enums.hpp.

◆ is_closing_template()

bool logit::is_closing_template ( crev_it_t left_it,
crev_it_t right_it )
inline

Checks if the '>' character is the closing of a template argument list.

Parameters
left_itIterator pointing to the '>' character.
right_itIterator pointing to the end of the string.
Returns
true if the '>' character closes a template argument list, false otherwise.

Definition at line 44 of file argument_utils.hpp.

◆ is_file()

bool logit::is_file ( const std::string & path)
inline

Checks if a path represents a file (by checking for an extension).

Parameters
pathThe path to check.
Returns
True if the path represents a file, false otherwise.

Definition at line 385 of file path_utils.hpp.

◆ make_otlp_record_snapshot()

OtlpRecordSnapshot logit::make_otlp_record_snapshot ( const LogRecord & record)
inline

Creates an owned snapshot from a LogRecord.

Parameters
recordSource log record.
Returns
Snapshot safe to store in async queues.

Definition at line 46 of file OtlpRecordSnapshot.hpp.

◆ make_prometheus_counter() [1/2]

PrometheusMetricFamily logit::make_prometheus_counter ( const std::string & name,
const std::string & help,
double value )
inline

Create a Counter metric family with one unlabeled sample.

Definition at line 41 of file PrometheusMetricBuilders.hpp.

◆ make_prometheus_counter() [2/2]

PrometheusMetricFamily logit::make_prometheus_counter ( const std::string & name,
const std::string & help,
double value,
std::vector< PrometheusLabel > labels )
inline

Create a Counter metric family with one labeled sample.

Definition at line 54 of file PrometheusMetricBuilders.hpp.

◆ make_prometheus_gauge() [1/2]

PrometheusMetricFamily logit::make_prometheus_gauge ( const std::string & name,
const std::string & help,
double value )
inline

Create a Gauge metric family with one unlabeled sample.

Definition at line 68 of file PrometheusMetricBuilders.hpp.

◆ make_prometheus_gauge() [2/2]

PrometheusMetricFamily logit::make_prometheus_gauge ( const std::string & name,
const std::string & help,
double value,
std::vector< PrometheusLabel > labels )
inline

Create a Gauge metric family with one labeled sample.

Definition at line 81 of file PrometheusMetricBuilders.hpp.

◆ make_prometheus_label()

PrometheusLabel logit::make_prometheus_label ( const std::string & name,
const std::string & value )
inline

Create a single label pair.

Definition at line 17 of file PrometheusMetricBuilders.hpp.

◆ make_prometheus_sample()

PrometheusSample logit::make_prometheus_sample ( const std::string & name,
double value,
std::vector< PrometheusLabel > labels = {},
int64_t timestamp_ms = 0 )
inline

Create a sample for a Prometheus metric family.

Definition at line 27 of file PrometheusMetricBuilders.hpp.

◆ make_prometheus_untyped() [1/2]

PrometheusMetricFamily logit::make_prometheus_untyped ( const std::string & name,
const std::string & help,
double value )
inline

Create an Untyped metric family with one unlabeled sample.

Definition at line 95 of file PrometheusMetricBuilders.hpp.

◆ make_prometheus_untyped() [2/2]

PrometheusMetricFamily logit::make_prometheus_untyped ( const std::string & name,
const std::string & help,
double value,
std::vector< PrometheusLabel > labels )
inline

Create an Untyped metric family with one labeled sample.

Definition at line 108 of file PrometheusMetricBuilders.hpp.

◆ make_relative()

std::string logit::make_relative ( const std::string & file_path,
const std::string & base_path )
inline

Computes the relative path from base_path to file_path.

Parameters
file_pathThe target file path.
base_pathThe base path from which to compute the relative path.
Returns
A string representing the relative path from base_path to file_path.

Definition at line 331 of file path_utils.hpp.

◆ otlp_json_escape()

std::string logit::otlp_json_escape ( const std::string & value)
inline

Escapes a string for JSON output.

Parameters
valueInput string.
Returns
Escaped JSON string content without surrounding quotes.

Definition at line 32 of file OtlpJsonSerializer.hpp.

◆ otlp_severity_number()

int logit::otlp_severity_number ( LogLevel level)
inline

Maps LogIt++ levels to OpenTelemetry severity numbers.

Parameters
levelLogIt++ severity level.
Returns
OpenTelemetry severity number.

Definition at line 66 of file OtlpJsonSerializer.hpp.

◆ otlp_thread_id_to_string()

std::string logit::otlp_thread_id_to_string ( const std::thread::id & id)
inline

Converts thread id to a portable string representation.

Parameters
idThread id to convert.
Returns
Stringified thread id.

Definition at line 37 of file OtlpRecordSnapshot.hpp.

◆ otlp_write_bool_attr()

void logit::otlp_write_bool_attr ( std::ostringstream & os,
const std::string & key,
bool value )
inline

Writes a bool OTLP attribute.

Parameters
osOutput stream.
keyAttribute key.
valueAttribute boolean value.

Definition at line 110 of file OtlpJsonSerializer.hpp.

◆ otlp_write_comma_if_needed()

void logit::otlp_write_comma_if_needed ( std::ostringstream & os,
bool & first )
inline

Writes a comma before the next JSON value when needed.

Parameters
osOutput stream.
firstFirst-item flag to update.

Definition at line 81 of file OtlpJsonSerializer.hpp.

◆ otlp_write_double_attr()

void logit::otlp_write_double_attr ( std::ostringstream & os,
const std::string & key,
double value )
inline

Writes a double OTLP attribute.

Parameters
osOutput stream.
keyAttribute key.
valueAttribute double value.

Definition at line 119 of file OtlpJsonSerializer.hpp.

◆ otlp_write_int_attr()

void logit::otlp_write_int_attr ( std::ostringstream & os,
const std::string & key,
int64_t value )
inline

Writes an int OTLP attribute.

Parameters
osOutput stream.
keyAttribute key.
valueAttribute integer value.

Definition at line 101 of file OtlpJsonSerializer.hpp.

◆ otlp_write_log_record_json()

void logit::otlp_write_log_record_json ( std::ostringstream & os,
const OtlpLogItem & item,
const OtlpJsonFormatConfig & config )
inline

Writes one OTLP JSON log record.

Parameters
osOutput stream.
itemLog item to serialize.
configExport configuration.

Definition at line 161 of file OtlpJsonSerializer.hpp.

◆ otlp_write_string_attr()

void logit::otlp_write_string_attr ( std::ostringstream & os,
const std::string & key,
const std::string & value )
inline

Writes a string OTLP attribute.

Parameters
osOutput stream.
keyAttribute key.
valueAttribute string value.

Definition at line 92 of file OtlpJsonSerializer.hpp.

◆ otlp_write_uint_attr()

void logit::otlp_write_uint_attr ( std::ostringstream & os,
const std::string & key,
uint64_t value )
inline

Writes a uint64 OTLP attribute.

Parameters
osOutput stream.
keyAttribute key.
valueAttribute uint64 value.

Definition at line 135 of file OtlpJsonSerializer.hpp.

◆ prometheus_escape_help()

std::string logit::prometheus_escape_help ( const std::string & value)
inline

Escapes help string for Prometheus text format.

Parameters
valueRaw help string.
Returns
Escaped string with backslash and newline escaped.

Definition at line 24 of file PrometheusTextSerializer.hpp.

◆ prometheus_escape_label_value()

std::string logit::prometheus_escape_label_value ( const std::string & value)
inline

Escapes label value for Prometheus text format.

Parameters
valueRaw label value.
Returns
Escaped string with backslash, double quote, and newline escaped.

Definition at line 43 of file PrometheusTextSerializer.hpp.

◆ prometheus_format_value()

void logit::prometheus_format_value ( std::ostringstream & os,
double value )
inline

Formats a Prometheus sample value according to text format rules.

Parameters
osOutput stream.
valueDouble value to format.

Definition at line 120 of file PrometheusTextSerializer.hpp.

◆ prometheus_sanitize_label_name()

std::string logit::prometheus_sanitize_label_name ( const std::string & name)
inline

Sanitizes a label name to match Prometheus naming rules.

Parameters
nameRaw label name.
Returns
Sanitized name; first char must be letter or underscore.

Definition at line 92 of file PrometheusTextSerializer.hpp.

◆ prometheus_sanitize_metric_name()

std::string logit::prometheus_sanitize_metric_name ( const std::string & name)
inline

Sanitizes a metric name to match Prometheus naming rules.

Parameters
nameRaw metric name.
Returns
Sanitized name: [a-zA-Z_:][a-zA-Z0-9_:]*; invalid chars replaced by _.

Definition at line 64 of file PrometheusTextSerializer.hpp.

◆ prometheus_write_metric_family()

void logit::prometheus_write_metric_family ( std::ostringstream & os,
const PrometheusMetricFamily & family,
const PrometheusTextFormatConfig & config )
inline

Writes one PrometheusMetricFamily to an output stream.

Parameters
osOutput string stream.
familyMetric family to write.
configFormat configuration.

Definition at line 138 of file PrometheusTextSerializer.hpp.

◆ sanitize_otlp_key()

std::string logit::sanitize_otlp_key ( const std::string & name)
inline

Sanitizes an attribute key for OTLP.

Parameters
nameRaw key name.
Returns
Sanitized key with invalid chars replaced by underscore.

Definition at line 147 of file OtlpJsonSerializer.hpp.

◆ split_arguments()

std::vector< std::string > logit::split_arguments ( const std::string & all_names)
inline

Splits a string of argument names into individual names, ignoring nested templates, parentheses, and quotes.

Parameters
all_namesThe string containing all argument names.
Returns
A vector of strings with individual argument names.

Definition at line 62 of file argument_utils.hpp.

◆ split_path()

PathComponents logit::split_path ( const std::string & path)
inline

Splits a path into its root and components.

Parameters
pathThe path to split.
Returns
A PathComponents object containing the root and components of the path.

Definition at line 287 of file path_utils.hpp.

◆ to_c_str() [1/2]

const char * logit::to_c_str ( LogLevel level,
int mode = 0 )
inline

Convert LogLevel to a C-style string representation.

Parameters
levelThe log level.
modeThe output mode (0 for full name, 1 for abbreviation).
Returns
C-style string representing the log level.

Definition at line 77 of file enums.hpp.

◆ to_c_str() [2/2]

const char * logit::to_c_str ( TextColor color)
inline

Convert TextColor to a C-style string (ANSI escape codes).

Parameters
colorThe text color.
Returns
C-style string representing the ANSI escape code for the color.

Definition at line 116 of file enums.hpp.

◆ to_string() [1/2]

std::string logit::to_string ( LogLevel level,
int mode = 0 )
inline

Convert LogLevel to a std::string representation.

Parameters
levelThe log level.
modeThe output mode (0 for full name, 1 for abbreviation).
Returns
std::string representing the log level.

Definition at line 109 of file enums.hpp.

◆ to_string() [2/2]

std::string logit::to_string ( TextColor color)
inline

Convert TextColor to a std::string (ANSI escape codes).

Parameters
colorThe text color.
Returns
std::string representing the ANSI escape code for the color.

Definition at line 143 of file enums.hpp.