Tesseract 0.28.4
Loading...
Searching...
No Matches
logging.h File Reference

Structured logging extensions for spdlog. More...

#include <spdlog/fmt/fmt.h>
#include <spdlog/logger.h>
#include <chrono>
#include <cstdint>
#include <functional>
#include <memory>
#include <string>
#include <string_view>
#include <thread>
#include <unordered_map>
#include <utility>
#include <variant>

Classes

struct  tesseract::common::LogRecord
 Structured representation of a Tesseract log event. More...
 

Namespaces

namespace  tesseract::common
 Namespace owning boost's hash_is_avalanching, and defined iff boost has the trait at all.
 

Macros

#define TESSERACT_LOG_SOURCE_LOCATION    spdlog::source_loc { __FILE__, __LINE__, SPDLOG_FUNCTION }
 Capture the current source file, line, and function for a log record.
 
#define TESSERACT_LOG_NAMED(name, severity, ...)    ::tesseract::common::detail::logNamed(name, spdlog::level::severity, TESSERACT_LOG_SOURCE_LOCATION, __VA_ARGS__)
 Emit a formatted structured record through a named logger.
 
#define TESSERACT_LOG_DEFAULT(severity, ...)    ::tesseract::common::detail::logDefault(spdlog::level::severity, TESSERACT_LOG_SOURCE_LOCATION, __VA_ARGS__)
 Emit a formatted structured record through the default logger.
 
#define TESSERACT_LOG_TRACE(...)   TESSERACT_LOG_DEFAULT(trace, __VA_ARGS__)
 Emit a trace record through the default tesseract logger.
 
#define TESSERACT_LOG_DEBUG(...)   TESSERACT_LOG_DEFAULT(debug, __VA_ARGS__)
 Emit a debug record through the default tesseract logger.
 
#define TESSERACT_LOG_INFO(...)   TESSERACT_LOG_DEFAULT(info, __VA_ARGS__)
 Emit an informational record through the default tesseract logger.
 
#define TESSERACT_LOG_WARN(...)   TESSERACT_LOG_DEFAULT(warn, __VA_ARGS__)
 Emit a warning record through the default tesseract logger.
 
#define TESSERACT_LOG_ERROR(...)   TESSERACT_LOG_DEFAULT(err, __VA_ARGS__)
 Emit an error record through the default tesseract logger.
 
#define TESSERACT_LOG_CRITICAL(...)   TESSERACT_LOG_DEFAULT(critical, __VA_ARGS__)
 Emit a critical record through the default tesseract logger.
 
#define TESSERACT_LOG_TRACE_NAMED(name, ...)   TESSERACT_LOG_NAMED(name, trace, __VA_ARGS__)
 Emit a trace record through a named logger.
 
#define TESSERACT_LOG_DEBUG_NAMED(name, ...)   TESSERACT_LOG_NAMED(name, debug, __VA_ARGS__)
 Emit a debug record through a named logger.
 
#define TESSERACT_LOG_INFO_NAMED(name, ...)   TESSERACT_LOG_NAMED(name, info, __VA_ARGS__)
 Emit an informational record through a named logger.
 
#define TESSERACT_LOG_WARN_NAMED(name, ...)   TESSERACT_LOG_NAMED(name, warn, __VA_ARGS__)
 Emit a warning record through a named logger.
 
#define TESSERACT_LOG_ERROR_NAMED(name, ...)   TESSERACT_LOG_NAMED(name, err, __VA_ARGS__)
 Emit an error record through a named logger.
 
#define TESSERACT_LOG_CRITICAL_NAMED(name, ...)   TESSERACT_LOG_NAMED(name, critical, __VA_ARGS__)
 Emit a critical record through a named logger.
 

Typedefs

using tesseract::common::LogAttribute = std::variant< bool, std::int64_t, std::uint64_t, double, std::string >
 Scalar value supported by a structured log-record attribute.
 
using tesseract::common::LogAttributes = std::unordered_map< std::string, LogAttribute >
 Collection of structured attributes indexed by attribute name.
 
using tesseract::common::LogRecordHandler = std::function< void(const LogRecord &)>
 Callback invoked for each structured record that passes spdlog filtering.
 
using tesseract::common::LogRecordHandlerId = std::uint64_t
 Opaque identifier assigned to a registered structured-record handler.
 

Functions

std::shared_ptr< spdlog::logger > tesseract::common::getLogger (std::string_view name="tesseract")
 Get the Tesseract-owned default logger or a registered named logger.
 
void tesseract::common::setLogger (std::shared_ptr< spdlog::logger > logger)
 Replace the default Tesseract logger.
 
bool tesseract::common::isLogLevelEnabled (spdlog::level::level_enum level) noexcept
 Check whether the default Tesseract logger accepts a severity.
 
LogRecordHandlerId tesseract::common::addLogRecordHandler (LogRecordHandler handler)
 Register a callback that receives structured log records.
 
bool tesseract::common::removeLogRecordHandler (LogRecordHandlerId id) noexcept
 Unregister a structured-record callback.
 
void tesseract::common::emitLogRecord (const LogRecord &record) noexcept
 Emit a structured record through its spdlog logger and all registered handlers.
 
spdlog::logger * tesseract::common::detail::getDefaultLogger () noexcept
 Get the default logger through the lock-free logging path.
 
void tesseract::common::detail::emitLogRecord (spdlog::logger &logger, const LogRecord &record) noexcept
 Emit a record through an already-resolved logger.
 
template<typename... Args>
void tesseract::common::detail::log (spdlog::logger &logger, spdlog::level::level_enum level, spdlog::source_loc source_location, fmt::format_string< Args... > format, Args &&... args) noexcept
 Format and emit a record for the Tesseract convenience macros.
 
template<typename... Args>
void tesseract::common::detail::logDefault (spdlog::level::level_enum level, spdlog::source_loc source_location, fmt::format_string< Args... > format, Args &&... args) noexcept
 Resolve the default logger and emit a formatted record.
 
template<typename... Args>
void tesseract::common::detail::logNamed (std::string_view logger_name, spdlog::level::level_enum level, spdlog::source_loc source_location, fmt::format_string< Args... > format, Args &&... args) noexcept
 Resolve a named logger and emit a formatted record.
 

Detailed Description

Structured logging extensions for spdlog.

Author
Levi Armstrong
Date
September 24, 2026
License
Software License Agreement (Apache License)
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Macro Definition Documentation

◆ TESSERACT_LOG_NAMED

#define TESSERACT_LOG_NAMED (   name,
  severity,
  ... 
)     ::tesseract::common::detail::logNamed(name, spdlog::level::severity, TESSERACT_LOG_SOURCE_LOCATION, __VA_ARGS__)

Emit a formatted structured record through a named logger.

Parameters
nameLogger name or expression convertible to std::string_view.
severityA native spdlog level token such as info, warn, or err.
...An fmt-compatible format string followed by its arguments.

Function Documentation

◆ log()

template<typename... Args>
void tesseract::common::detail::log ( spdlog::logger &  logger,
spdlog::level::level_enum  level,
spdlog::source_loc  source_location,
fmt::format_string< Args... >  format,
Args &&...  args 
)
noexcept

Format and emit a record for the Tesseract convenience macros.

Native spdlog filtering is checked before formatting. A formatting exception is converted to a fallback message so logging remains nonthrowing.

Template Parameters
ArgsTypes of the format arguments.
Parameters
loggerDestination logger.
levelNative spdlog severity.
source_locationSource location captured by the calling macro.
formatCompile-time checked fmt format string.
argsValues referenced by format.