iceberg-cpp
Loading...
Searching...
No Matches
cerr_logger.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
24
25#include <atomic>
26#include <mutex>
27
28#include "iceberg/iceberg_export.h"
31
32namespace iceberg {
33
40class ICEBERG_EXPORT CerrLogger : public Logger {
41 public:
42 explicit CerrLogger(LogLevel level = LogLevel::kInfo) : level_(level) {}
43
44 bool ShouldLog(LogLevel level) const noexcept override {
45 return level >= level_.load(std::memory_order_relaxed);
46 }
47 void Log(LogMessage&& message) noexcept override;
48 void SetLevel(LogLevel level) noexcept override {
49 level_.store(level, std::memory_order_relaxed);
50 }
51 LogLevel level() const noexcept override {
52 return level_.load(std::memory_order_relaxed);
53 }
54 void Flush() noexcept override;
55
56 private:
57 std::atomic<LogLevel> level_;
58 std::mutex mutex_;
59};
60
61} // namespace iceberg
Logger that writes one line per record to std::cerr.
Definition cerr_logger.h:40
bool ShouldLog(LogLevel level) const noexcept override
Cheap check whether a record at level would be emitted.
Definition cerr_logger.h:44
LogLevel level() const noexcept override
Return the minimum level this logger emits.
Definition cerr_logger.h:51
void SetLevel(LogLevel level) noexcept override
Set the minimum level this logger emits.
Definition cerr_logger.h:48
Pluggable logging sink.
Definition logger.h:145
Severity levels for the logging system.
LogLevel
Logging severity level, ordered from most to least verbose.
Definition log_level.h:38
Pluggable logging interface and the process-global default logger.
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
STL namespace.
A single log record handed to a Logger.
Definition logger.h:64