iceberg-cpp
Loading...
Searching...
No Matches
log_level.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 <string_view>
26#include <utility>
27
29#include "iceberg/result.h"
31
32namespace iceberg {
33
39enum class LogLevel {
40 kTrace,
41 kDebug,
42 kInfo,
43 kWarn,
44 kError,
45 kCritical,
46 kFatal,
47 kOff,
48};
49
51constexpr std::string_view ToString(LogLevel level) noexcept {
52 switch (level) {
53 case LogLevel::kTrace:
54 return "trace";
55 case LogLevel::kDebug:
56 return "debug";
57 case LogLevel::kInfo:
58 return "info";
59 case LogLevel::kWarn:
60 return "warn";
61 case LogLevel::kError:
62 return "error";
63 case LogLevel::kCritical:
64 return "critical";
65 case LogLevel::kFatal:
66 return "fatal";
67 case LogLevel::kOff:
68 return "off";
69 }
71}
72
78inline Result<LogLevel> LogLevelFromString(std::string_view s) {
79 auto level = StringUtils::ToLower(s);
80 if (level == "trace") return LogLevel::kTrace;
81 if (level == "debug") return LogLevel::kDebug;
82 if (level == "info") return LogLevel::kInfo;
83 if (level == "warn") return LogLevel::kWarn;
84 if (level == "error") return LogLevel::kError;
85 if (level == "critical") return LogLevel::kCritical;
86 if (level == "fatal") return LogLevel::kFatal;
87 if (level == "off") return LogLevel::kOff;
88 return InvalidArgument("Invalid log level: {}", s);
89}
90
91} // namespace iceberg
static std::string ToLower(std::string_view str)
Lower-case a UTF-8 string using Unicode simple (1:1) case mapping.
Definition expected.h:1199
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:34
ICEBERG_EXPORT std::string_view ToString(Expression::Operation op)
Returns a string representation of an expression operation.
void unreachable() noexcept
Marks a branch the program can never take.
Definition unreachable.h:35
Result< LogLevel > LogLevelFromString(std::string_view s)
Parse a LogLevel from a string (case-insensitive).
Definition log_level.h:78
LogLevel
Logging severity level, ordered from most to least verbose.
Definition log_level.h:39
Define Result, Status, and error helpers.
Provide string utility helpers.
Portable stand-in for std::unreachable.