kamcheungting-db commented on code in PR #723: URL: https://github.com/apache/iceberg-cpp/pull/723#discussion_r3449310193
########## src/iceberg/logging/logger.h: ########## @@ -0,0 +1,369 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +#pragma once + +/// \file iceberg/logging/logger.h +/// \brief Pluggable logging interface and the process-global default logger. +/// +/// This header is backend-agnostic: it never includes the build-generated +/// backend configuration header and never references the spdlog feature macro, +/// so consumers see one stable API regardless of how the backend was configured. + +#include <concepts> +#include <cstdlib> +#include <format> +#include <memory> +#include <source_location> +#include <string> +#include <string_view> +#include <type_traits> +#include <unordered_map> +#include <utility> +#include <vector> + +#include "iceberg/iceberg_export.h" +#include "iceberg/logging/log_level.h" +#include "iceberg/result.h" + +namespace iceberg { + +/// \brief A structured key/value attribute attached to a log record. +/// +/// Both key and value are owned so a sink may retain the record safely. Engine +/// loggers can surface these as discrete fields (query id, task id, table name, +/// snapshot id, file path, ...); see LogMessage::Builder to populate them. +struct ICEBERG_EXPORT LogAttribute { + std::string key; + std::string value; +}; + +/// \brief A single log record handed to a Logger. +/// +/// The formatted message is owned (moved in by the logging macros), so a sink +/// may safely retain the record beyond the Log() call. The member set must not +/// depend on the build's logging backend (the spdlog backend never appears here). +/// Use LogMessage::Builder for a readable way to assemble one, especially with +/// structured attributes. +struct ICEBERG_EXPORT LogMessage { + LogLevel level = LogLevel::kOff; + std::string message; + std::source_location location = std::source_location::current(); + std::vector<LogAttribute> attributes; + + class Builder; +}; + +/// \brief Fluent builder for LogMessage, the easy path to attach structured +/// attributes. +/// +/// Example: +/// auto record = LogMessage::Builder(LogLevel::kInfo) +/// .Message("scan finished") +/// .Attribute("table", table_name) +/// .Attribute("snapshot_id", std::to_string(id)) +/// .Build(); +/// logger->Log(std::move(record)); +/// +/// The location defaults to where the Builder is constructed; override it with +/// Location() (e.g. to forward a caller's std::source_location). +class ICEBERG_EXPORT LogMessage::Builder { + public: + explicit Builder(LogLevel level) : level_(level) {} Review Comment: Done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
