Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
log_level.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2024, kcenon
3
10#pragma once
11
12#include <cstdint>
13#include <string_view>
14
15namespace kcenon::thread {
16
27enum class log_level_v2 : uint8_t {
28 trace = 0,
29 debug = 1,
30 info = 2,
31 warn = 3,
32 error = 4,
33 critical = 5,
34 off = 6
35};
36
40constexpr std::string_view to_string(log_level_v2 level) noexcept {
41 switch (level) {
42 case log_level_v2::trace: return "TRACE";
43 case log_level_v2::debug: return "DEBUG";
44 case log_level_v2::info: return "INFO";
45 case log_level_v2::warn: return "WARN";
46 case log_level_v2::error: return "ERROR";
47 case log_level_v2::critical: return "CRITICAL";
48 case log_level_v2::off: return "OFF";
49 default: return "UNKNOWN";
50 }
51}
52
53// ============================================================================
54// Legacy log_level compatibility
55// ============================================================================
56// Note: Legacy log_level from thread_logger.h is deprecated.
57// Use log_level_v2 or common::interfaces::log_level instead.
58// See Issue #261 for migration details.
59
65constexpr bool should_log(log_level_v2 message_level, log_level_v2 min_level) noexcept {
66 if (min_level == log_level_v2::off) {
67 return false;
68 }
69 return static_cast<uint8_t>(message_level) >= static_cast<uint8_t>(min_level);
70}
71
75inline log_level_v2 parse_log_level(std::string_view str) noexcept {
76 if (str == "trace" || str == "TRACE") return log_level_v2::trace;
77 if (str == "debug" || str == "DEBUG") return log_level_v2::debug;
78 if (str == "info" || str == "INFO") return log_level_v2::info;
79 if (str == "warn" || str == "WARN" || str == "warning" || str == "WARNING")
80 return log_level_v2::warn;
81 if (str == "error" || str == "ERROR") return log_level_v2::error;
82 if (str == "critical" || str == "CRITICAL" || str == "fatal" || str == "FATAL")
84 if (str == "off" || str == "OFF") return log_level_v2::off;
85 return log_level_v2::info; // default
86}
87
88} // namespace kcenon::thread
Represents an error in the thread system.
@ critical
At or above max_size, queue is full.
Core threading foundation of the thread system library.
Definition thread_impl.h:17
log_level_v2 parse_log_level(std::string_view str) noexcept
Parse string to log_level_v2.
Definition log_level.h:75
log_level_v2
Logging severity levels with explicit ascending values.
Definition log_level.h:27
@ trace
Finest-grained informational events.
@ warn
Potentially harmful situations.
@ off
Special level to disable logging.
@ critical
Severe error events that lead to termination.
@ debug
Fine-grained informational events for debugging.
@ info
Informational messages highlighting progress.
@ error
Error events that might still allow continuation.
constexpr std::string_view to_string(log_level_v2 level) noexcept
Convert log_level_v2 to string representation.
Definition log_level.h:40
constexpr bool should_log(log_level_v2 message_level, log_level_v2 min_level) noexcept
Check if a log level should be logged given a minimum level.
Definition log_level.h:65