plugify 1.0.0.0
Loading...
Searching...
No Matches
log.hpp
1#pragma once
2
3#include <cstdint>
4#include <string_view>
5
6namespace plugify {
11 enum class Severity : uint8_t {
12 None = 0,
13 Fatal = 1,
14 Error = 2,
15 Warning = 3,
16 Info = 4,
17 Debug = 5,
18 Verbose = 6,
19 };
20
28 class ILogger {
29 public:
30 virtual ~ILogger() = default;
31
37 virtual void Log(std::string_view msg, Severity severity) = 0;
38 };
39
43 namespace SeverityUtils {
49 constexpr std::string_view ToString(Severity severity) noexcept {
50 switch (severity) {
51 case Severity::Fatal: return "Fatal";
52 case Severity::Error: return "Error";
53 case Severity::Warning: return "Warning";
54 case Severity::Info: return "Info";
55 case Severity::Debug: return "Debug";
56 case Severity::Verbose: return "Verbose";
57 default: return "None";
58 }
59 }
60
66 constexpr Severity FromString(std::string_view severity) noexcept {
67 if (severity == "Fatal") {
68 return Severity::Fatal;
69 } else if (severity == "Error") {
70 return Severity::Error;
71 } else if (severity == "Warning") {
72 return Severity::Warning;
73 } else if (severity == "Info") {
74 return Severity::Info;
75 } else if (severity == "Debug") {
76 return Severity::Debug;
77 } else if (severity == "Verbose") {
78 return Severity::Verbose;
79 }
80 return Severity::None;
81 }
82 } // namespace SeverityUtils
83
84} // namespace plugify
Interface for logging messages with different severity levels.
Definition log.hpp:28
virtual void Log(std::string_view msg, Severity severity)=0
Log a message with the specified severity level.
constexpr std::string_view ToString(Severity severity) noexcept
Convert a Severity enum value to its string representation.
Definition log.hpp:49
constexpr Severity FromString(std::string_view severity) noexcept
Convert a string representation to a Severity enum value.
Definition log.hpp:66