iceberg-cpp
Loading...
Searching...
No Matches
Namespaces | Macros | Functions
log_macros.h File Reference

Iceberg-prefixed logging macros (ICEBERG_LOG_*). More...

#include <cstdlib>
#include <format>
#include <memory>
#include <source_location>
#include <string>
#include <string_view>
#include <utility>
#include "iceberg/logging/log_level.h"
#include "iceberg/logging/logger.h"

Go to the source code of this file.

Namespaces

namespace  iceberg
 Core Apache Iceberg C++ APIs.
 

Macros

#define ICEBERG_LOG_ACTIVE_LEVEL   ::iceberg::LogLevel::kTrace
 Compile-time severity floor: statements below this level are discarded via if constexpr, so no emit code runs and no format call / source_location is generated for them (the compiler is free to optimize the dead branch away). The statement must still be well-formed – a bad format string or a non-formattable argument is a compile error even when the branch is discarded. Defaults to keeping everything. ICEBERG_LOG_FATAL is never gated by this floor – its abort is always compiled in.
 
#define ICEBERG_INTERNAL_LOG_MESSAGE(FMT_, ...)    [&]() -> ::std::string { return ::std::format((FMT_)__VA_OPT__(, ) __VA_ARGS__); }
 
#define ICEBERG_INTERNAL_LOG(level_, FMT_, ...)
 
#define ICEBERG_LOG_TRACE(...)    ICEBERG_INTERNAL_LOG(::iceberg::LogLevel::kTrace, __VA_ARGS__)
 
#define ICEBERG_LOG_DEBUG(...)    ICEBERG_INTERNAL_LOG(::iceberg::LogLevel::kDebug, __VA_ARGS__)
 
#define ICEBERG_LOG_INFO(...)    ICEBERG_INTERNAL_LOG(::iceberg::LogLevel::kInfo, __VA_ARGS__)
 
#define ICEBERG_LOG_WARN(...)    ICEBERG_INTERNAL_LOG(::iceberg::LogLevel::kWarn, __VA_ARGS__)
 
#define ICEBERG_LOG_ERROR(...)    ICEBERG_INTERNAL_LOG(::iceberg::LogLevel::kError, __VA_ARGS__)
 
#define ICEBERG_LOG_CRITICAL(...)    ICEBERG_INTERNAL_LOG(::iceberg::LogLevel::kCritical, __VA_ARGS__)
 
#define ICEBERG_LOG_FATAL(FMT_, ...)
 
#define ICEBERG_LOG(level_, FMT_, ...)
 
#define ICEBERG_LOG_TO(logger_, level_, FMT_, ...)
 
#define ICEBERG_LOG_RUNTIME_FMT(level_, FMT_, ...)
 

Functions

template<typename... Args>
std::string iceberg::internal::VFormat (std::string_view fmt, Args &&... args)
 Runtime (non-literal) format-string helper for ICEBERG_LOG_RUNTIME_FMT.
 
template<typename MakeMessage >
void iceberg::internal::EmitIfEnabled (Logger &logger, LogLevel level, const std::source_location &location, MakeMessage &&make_message) noexcept
 Gate on logger.ShouldLog, then format (via make_message) and emit.
 
template<typename MakeMessage >
void iceberg::internal::LogToCurrent (LogLevel level, const std::source_location &location, MakeMessage &&make_message) noexcept
 Emit to the current (scoped-or-default) logger if enabled.
 
template<typename MakeMessage >
void iceberg::internal::DispatchFatal (Logger *logger, const std::source_location &location, MakeMessage &&make_message) noexcept
 Format once, emit if enabled, flush, run the fatal handler, and abort.
 
template<typename MakeMessage >
void iceberg::internal::LogToCurrentRuntime (LogLevel level, const std::source_location &location, MakeMessage &&make_message) noexcept
 
template<typename MakeMessage >
void iceberg::internal::LogToExplicitRuntime (Logger &logger, LogLevel level, const std::source_location &location, MakeMessage &&make_message) noexcept
 
template<typename MakeMessage >
void iceberg::internal::LogFatal (const std::source_location &location, MakeMessage &&make_message) noexcept
 

Detailed Description

Iceberg-prefixed logging macros (ICEBERG_LOG_*).

Kept out of logger.h so consumers of the C++ logging API (Logger, Log(), ScopedLogger) are not forced to pull in these macros or the conforming preprocessor they require. Include this header to use the macros; include short_log_macros.h for the bare LOG_* aliases.

Macro Definition Documentation

◆ ICEBERG_INTERNAL_LOG

#define ICEBERG_INTERNAL_LOG (   level_,
  FMT_,
  ... 
)
Value:
do { \
if constexpr ((level_) >= ICEBERG_LOG_ACTIVE_LEVEL) { \
::iceberg::internal::LogToCurrent( \
(level_), ::std::source_location::current(), \
ICEBERG_INTERNAL_LOG_MESSAGE(FMT_ __VA_OPT__(, ) __VA_ARGS__)); \
} \
} while (0)
#define ICEBERG_LOG_ACTIVE_LEVEL
Compile-time severity floor: statements below this level are discarded via if constexpr,...
Definition log_macros.h:184

◆ ICEBERG_LOG

#define ICEBERG_LOG (   level_,
  FMT_,
  ... 
)
Value:
::iceberg::internal::LogToCurrentRuntime( \
(level_), ::std::source_location::current(), \
ICEBERG_INTERNAL_LOG_MESSAGE(FMT_ __VA_OPT__(, ) __VA_ARGS__))

◆ ICEBERG_LOG_FATAL

#define ICEBERG_LOG_FATAL (   FMT_,
  ... 
)
Value:
::iceberg::internal::LogFatal( \
::std::source_location::current(), \
ICEBERG_INTERNAL_LOG_MESSAGE(FMT_ __VA_OPT__(, ) __VA_ARGS__))

◆ ICEBERG_LOG_RUNTIME_FMT

#define ICEBERG_LOG_RUNTIME_FMT (   level_,
  FMT_,
  ... 
)
Value:
::iceberg::internal::LogToCurrentRuntime( \
(level_), ::std::source_location::current(), [&]() -> ::std::string { \
return ::iceberg::internal::VFormat((FMT_)__VA_OPT__(, ) __VA_ARGS__); \
})

◆ ICEBERG_LOG_TO

#define ICEBERG_LOG_TO (   logger_,
  level_,
  FMT_,
  ... 
)
Value:
::iceberg::internal::LogToExplicitRuntime( \
(logger_), (level_), ::std::source_location::current(), \
ICEBERG_INTERNAL_LOG_MESSAGE(FMT_ __VA_OPT__(, ) __VA_ARGS__))

Function Documentation

◆ DispatchFatal()

template<typename MakeMessage >
void iceberg::internal::DispatchFatal ( Logger logger,
const std::source_location &  location,
MakeMessage &&  make_message 
)
noexcept

Format once, emit if enabled, flush, run the fatal handler, and abort.

Formatting is independent of ShouldLog so the handler always receives the message. logger may be null.

◆ EmitIfEnabled()

template<typename MakeMessage >
void iceberg::internal::EmitIfEnabled ( Logger logger,
LogLevel  level,
const std::source_location &  location,
MakeMessage &&  make_message 
)
noexcept

Gate on logger.ShouldLog, then format (via make_message) and emit.

make_message is a callable returning the formatted std::string; it is invoked only after the level passes ShouldLog, so a disabled log never evaluates its format arguments. Never throws: a std::formatter that throws (any type) routes to EmitFormatError, so the noexcept logging contract holds.

◆ VFormat()

template<typename... Args>
std::string iceberg::internal::VFormat ( std::string_view  fmt,
Args &&...  args 
)

Runtime (non-literal) format-string helper for ICEBERG_LOG_RUNTIME_FMT.

std::format requires a compile-time format string; this routes a runtime string through std::vformat. Args are bound as named lvalues and the arg-store is held in a named variable so it outlives the vformat call (C++23 make_format_args rejects rvalues – P2905 / LWG3631).