-
Notifications
You must be signed in to change notification settings - Fork 123
Expand file tree
/
Copy pathspdlog_logger.h
More file actions
90 lines (75 loc) · 3.4 KB
/
Copy pathspdlog_logger.h
File metadata and controls
90 lines (75 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* 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/internal/spdlog_logger.h
/// \brief spdlog-backed logging sink.
///
/// INTERNAL, NOT INSTALLED. Included only from .cc files (logger.cc and
/// spdlog_logger.cc). It pulls in the build-generated config.h itself and gates
/// its entire body on ICEBERG_HAS_SPDLOG, so it compiles to nothing unless the
/// project was built with ICEBERG_SPDLOG=ON. SpdLogger is not a
/// consumer-constructible public type -- applications obtain it via the default
/// logger or the "logger-impl"="spdlog" registry factory.
#include "iceberg/logging/config.h"
#ifdef ICEBERG_HAS_SPDLOG
# include <atomic>
# include <memory>
# include <spdlog/logger.h>
# include "iceberg/logging/log_level.h"
# include "iceberg/logging/logger.h"
namespace iceberg::internal {
/// \brief Logger backed by spdlog (synchronous only in v1).
///
/// Synchronous because spdlog::source_loc holds non-owning const char* that are
/// unsafe to forward into an async logger (spdlog #3227).
/// ICEBERG_EXPORT so the symbol is linkable from in-tree tests (and any
/// internal consumer) under -fvisibility=hidden / MSVC DLL builds. The header
/// is still not installed -- this is a binary-visibility detail, not public API.
class ICEBERG_EXPORT SpdLogger : public Logger {
public:
/// \brief Construct over a default stderr-backed spdlog logger.
explicit SpdLogger(LogLevel level = LogLevel::kInfo);
/// \brief Construct over a caller-provided spdlog logger.
///
/// The logger MUST be synchronous. Log() forwards spdlog::source_loc, which
/// borrows the std::source_location's const char* pointers; an async spdlog
/// logger would queue them past their lifetime (spdlog #3227 -> UB). This is a
/// caller contract -- spdlog exposes no reliable sync/async query to assert on.
explicit SpdLogger(std::shared_ptr<spdlog::logger> logger,
LogLevel level = LogLevel::kInfo);
/// \brief Apply the "pattern" property (spdlog set_pattern), then "level".
Status Initialize(
const std::unordered_map<std::string, std::string>& properties) override;
bool ShouldLog(LogLevel level) const noexcept override {
return level >= level_.load(std::memory_order_relaxed);
}
void Log(LogMessage&& message) noexcept override;
void SetLevel(LogLevel level) noexcept override {
level_.store(level, std::memory_order_relaxed);
}
LogLevel level() const noexcept override {
return level_.load(std::memory_order_relaxed);
}
void Flush() noexcept override;
private:
std::shared_ptr<spdlog::logger> logger_;
std::atomic<LogLevel> level_;
};
} // namespace iceberg::internal
#endif // ICEBERG_HAS_SPDLOG