Branch data Line data Source code
1 : : // Copyright 2026 HPActor Contributors
2 : : //
3 : : // Licensed under the Apache License, Version 2.0 (the "License");
4 : : // you may not use this file except in compliance with the License.
5 : : // You may obtain a copy of the License at
6 : : //
7 : : // http://www.apache.org/licenses/LICENSE-2.0
8 : : //
9 : : // Unless required by applicable law or agreed to in writing, software
10 : : // distributed under the License is distributed on an "AS IS" BASIS,
11 : : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : : // See the License for the specific language governing permissions and
13 : : // limitations under the License.
14 : :
15 : : #include <hpactor/log/log_category.hpp>
16 : :
17 : : namespace hpactor::log {
18 : :
19 : 590 : [[nodiscard]] const char* to_string(LogCategory category) noexcept {
20 : 590 : switch (category) {
21 : : // NOLINTBEGIN(cppcoreguidelines-macro-usage)
22 : : #define HPACTOR_LOG_CATEGORY_TO_STRING(name, str) \
23 : : case LogCategory::name: \
24 : : return str;
25 : 590 : HPACTOR_LOG_CATEGORIES(HPACTOR_LOG_CATEGORY_TO_STRING)
26 : : #undef HPACTOR_LOG_CATEGORY_TO_STRING
27 : : // NOLINTEND(cppcoreguidelines-macro-usage)
28 : 0 : case LogCategory::kCount:
29 : 0 : return "count";
30 : : }
31 : 0 : return "unknown";
32 : : }
33 : :
34 : 19 : [[nodiscard]] const char* to_string(LogEventId id) noexcept {
35 : 19 : switch (id) {
36 : : // NOLINTBEGIN(cppcoreguidelines-macro-usage)
37 : : #define HPACTOR_LOG_EVENT_TO_STRING(name, value, str) \
38 : : case LogEventId::name: \
39 : : return str;
40 : 17 : HPACTOR_LOG_EVENTS(HPACTOR_LOG_EVENT_TO_STRING)
41 : : #undef HPACTOR_LOG_EVENT_TO_STRING
42 : : // NOLINTEND(cppcoreguidelines-macro-usage)
43 : : }
44 : 2 : return "unknown_event";
45 : : }
46 : :
47 : 18 : [[nodiscard]] result<LogCategory> parse_category(std::string_view value) noexcept {
48 : : // NOLINTBEGIN(cppcoreguidelines-macro-usage)
49 : : #define HPACTOR_LOG_CATEGORY_PARSE(name, str) \
50 : : if ((value) == (str)) \
51 : : return result<LogCategory>::make(LogCategory::name);
52 : 18 : HPACTOR_LOG_CATEGORIES(HPACTOR_LOG_CATEGORY_PARSE)
53 : : #undef HPACTOR_LOG_CATEGORY_PARSE
54 : : // NOLINTEND(cppcoreguidelines-macro-usage)
55 : 3 : return result<LogCategory>::make(error(errors::unknown, "unknown log "
56 : 1 : "category"));
57 : : }
58 : :
59 : : } // namespace hpactor::log
|