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
28#include "iceberg/result.h"
29#include "iceberg/util/string_util.h"
30
31namespace iceberg {
32
38enum class LogLevel {
39 kTrace,
40 kDebug,
41 kInfo,
42 kWarn,
43 kError,
44 kCritical,
45 kFatal,
46 kOff,
47};
48
50constexpr std::string_view ToString(LogLevel level) noexcept {
51 switch (level) {
52 case LogLevel::kTrace:
53 return "trace";
54 case LogLevel::kDebug:
55 return "debug";
56 case LogLevel::kInfo:
57 return "info";
58 case LogLevel::kWarn:
59 return "warn";
60 case LogLevel::kError:
61 return "error";
62 case LogLevel::kCritical:
63 return "critical";
64 case LogLevel::kFatal:
65 return "fatal";
66 case LogLevel::kOff:
67 return "off";
68 }
69 std::unreachable();
70}
71
77inline Result<LogLevel> LogLevelFromString(std::string_view s) {
78 auto level = StringUtils::ToLower(s);
79 if (level == "trace") return LogLevel::kTrace;
80 if (level == "debug") return LogLevel::kDebug;
81 if (level == "info") return LogLevel::kInfo;
82 if (level == "warn") return LogLevel::kWarn;
83 if (level == "error") return LogLevel::kError;
84 if (level == "critical") return LogLevel::kCritical;
85 if (level == "fatal") return LogLevel::kFatal;
86 if (level == "off") return LogLevel::kOff;
87 return InvalidArgument("Invalid log level: {}", s);
88}
89
90} // namespace iceberg
Result< LogLevel > LogLevelFromString(std::string_view s)
Parse a LogLevel from a string (case-insensitive).
Definition log_level.h:77
LogLevel
Logging severity level, ordered from most to least verbose.
Definition log_level.h:38