Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
mcp_logging.h
1#ifndef SOURCEMETA_CORE_MCP_LOGGING_H_
2#define SOURCEMETA_CORE_MCP_LOGGING_H_
3
4#include <sourcemeta/core/json.h>
5
6#include <array> // std::array
7#include <cstdint> // std::uint8_t
8#include <optional> // std::optional, std::nullopt
9#include <utility> // std::unreachable
10
11namespace sourcemeta::core {
12
44
58[[nodiscard]] constexpr auto
60 switch (level) {
62 return "debug";
64 return "info";
66 return "notice";
68 return "warning";
70 return "error";
72 return "critical";
74 return "alert";
76 return "emergency";
77 }
78 // Clang settles that no other value arrives, so only GCC and MSVC
79 // need to be told that the end of this function is never reached
80#if !defined(__clang__)
81 std::unreachable();
82#endif
83}
84
102[[nodiscard]] constexpr auto
104 -> std::optional<MCPLogLevel> {
105 constexpr std::array<MCPLogLevel, 8> LEVELS{
109 for (const auto level : LEVELS) {
110 if (mcp_log_level_string(level) == value) {
111 return level;
112 }
113 }
114 return std::nullopt;
115}
116
139[[nodiscard]] constexpr auto
141 const MCPLogLevel threshold) noexcept -> bool {
142 return level >= threshold;
143}
144
145} // namespace sourcemeta::core
146#endif
Definition error_base.h:48
std::basic_string_view< Char, CharTraits > StringView
The string view type used by the JSON document.
Definition json_value.h:54
constexpr auto mcp_log_level_enabled(const MCPLogLevel level, const MCPLogLevel threshold) noexcept -> bool
Definition mcp_logging.h:140
MCPLogLevel
Definition mcp_logging.h:26
constexpr auto mcp_log_level_string(const MCPLogLevel level) noexcept -> JSON::StringView
Definition mcp_logging.h:59
constexpr auto mcp_resolve_log_level(const JSON::StringView value) noexcept -> std::optional< MCPLogLevel >
Definition mcp_logging.h:103
@ Warning
Conditions that may require attention.
Definition mcp_logging.h:34
@ Notice
Normal but significant conditions.
Definition mcp_logging.h:32
@ Critical
Critical conditions.
Definition mcp_logging.h:38
@ Info
General informational messages.
Definition mcp_logging.h:30
@ Error
Error conditions.
Definition mcp_logging.h:36
@ Emergency
Conditions indicating that the system is unusable.
Definition mcp_logging.h:42
@ Debug
Detailed information useful for debugging.
Definition mcp_logging.h:28
@ Alert
Conditions requiring immediate action.
Definition mcp_logging.h:40