iceberg-cpp
Loading...
Searching...
No Matches
Public Member Functions | List of all members
iceberg::ScopedLogger Class Reference

Bind a logger for the current thread until this object leaves scope. More...

#include <logger.h>

Public Member Functions

 ScopedLogger (std::shared_ptr< Logger > logger) noexcept
 
 ScopedLogger (const ScopedLogger &)=delete
 
ScopedLoggeroperator= (const ScopedLogger &)=delete
 
 ScopedLogger (ScopedLogger &&)=delete
 
ScopedLoggeroperator= (ScopedLogger &&)=delete
 

Detailed Description

Bind a logger for the current thread until this object leaves scope.

The default logging path on this thread – CurrentLogger(), Log(level, ...), and the LOG_* macros – routes to logger instead of the global default; explicit Log(logger, ...) is unaffected. Bindings nest and restore on exit, and nullptr masks any enclosing binding back to the global default. Lets an engine route Iceberg's own logs into a per catalog/session/query/task context with no call-site changes.

auto query_log = std::make_shared<MySink>();
iceberg::ScopedLogger bind(query_log); // this thread, this scope
iceberg::Log(LogLevel::kInfo, "scan {}", id); // -> query_log
Bind a logger for the current thread until this object leaves scope.
Definition logger.h:235
void Log(LogLevel level, internal::FmtWithLoc< std::type_identity_t< Args >... > fmt, Args &&... args) noexcept
Log to the process-default logger, std::format style. Formats only if the level is enabled; never thr...
Definition logger.h:354

Stack-only and same-thread (non-copyable, non-movable). For thread pools, capture on the submitting thread and re-bind on the worker:

auto captured = iceberg::GetCurrentLogger();
pool.submit([captured, work] { iceberg::ScopedLogger bind(captured); work(); });

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