LogIt++
Loading...
Searching...
No Matches
Enums.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef _LOGIT_ENUMS_HPP_INCLUDED
3#define _LOGIT_ENUMS_HPP_INCLUDED
6
7#include <array>
8#include <string>
9
10namespace logit {
11
22
25 enum class TextColor {
26 Black,
27 DarkRed,
35 Red,
36 Green,
37 Yellow,
38 Blue,
39 Magenta,
40 Cyan,
41 White,
42 };
43
52
57 inline const char* to_c_str(const LogLevel& level, const int& mode = 0) {
58 static const std::array<const char*, 6> data_str_0 = {
59 "TRACE",
60 "DEBUG",
61 "INFO",
62 "WARN",
63 "ERROR",
64 "FATAL"
65 };
66 static const std::array<const char*, 6> data_str_1 = {
67 "T",
68 "D",
69 "I",
70 "W",
71 "E",
72 "F"
73 };
74 switch (mode) {
75 case 0:
76 return data_str_0[static_cast<size_t>(level)];
77 case 1:
78 return data_str_1[static_cast<size_t>(level)];
79 default:
80 break;
81 };
82 return data_str_0[static_cast<size_t>(level)];
83 }
84
89 inline std::string to_string(const LogLevel& level, const int& mode = 0) {
90 return std::string(to_c_str(level, mode));
91 }
92
96 inline const char* to_c_str(const TextColor& color) {
97 static const std::array<const char*, 16> ansi_codes = {
98 "\033[30m", // Black
99 "\033[31m", // DarkRed
100 "\033[32m", // DarkGreen
101 "\033[33m", // DarkYellow
102 "\033[34m", // DarkBlue
103 "\033[35m", // DarkMagenta
104 "\033[36m", // DarkCyan
105 "\033[37m", // LightGray
106 "\033[90m", // DarkGray
107 "\033[91m", // Red
108 "\033[92m", // Green
109 "\033[93m", // Yellow
110 "\033[94m", // Blue
111 "\033[95m", // Magenta
112 "\033[96m", // Cyan
113 "\033[97m" // White
114 };
115
116 // Преобразуем TextColor в строку с ANSI кодом
117 return ansi_codes[static_cast<int>(color)];
118 }
119
124 inline std::string to_string(const TextColor& color) {
125 return std::string(to_c_str(color));
126 }
127
131 inline std::string get_log_level_color(const LogLevel& log_level) {
132 switch (log_level) {
145 default:
146 break;
147 }
149 }
150
151}; // namespace logit
152
153#endif // _LOGIT_ENUMS_HPP_INCLUDED
#define LOGIT_COLOR_DEBUG
#define LOGIT_COLOR_DEFAULT
#define LOGIT_COLOR_TRACE
#define LOGIT_COLOR_WARN
#define LOGIT_COLOR_ERROR
#define LOGIT_COLOR_FATAL
#define LOGIT_COLOR_INFO
The primary namespace for the LogIt++ library.
const char * to_c_str(const LogLevel &level, const int &mode=0)
Convert LogLevel to a C-style string representation.
Definition Enums.hpp:57
LogLevel
Logging levels.
Definition Enums.hpp:14
@ LOG_LVL_TRACE
Trace level logging.
@ LOG_LVL_ERROR
Error level logging.
@ LOG_LVL_INFO
Information level logging.
@ LOG_LVL_FATAL
Fatal level logging.
@ LOG_LVL_DEBUG
Debug level logging.
@ LOG_LVL_WARN
Warning level logging.
std::string to_string(const LogLevel &level, const int &mode=0)
Convert LogLevel to a std::string representation.
Definition Enums.hpp:89
LoggerParam
Enumeration for different logger parameters that can be retrieved.
Definition Enums.hpp:46
@ TimeSinceLastLog
The time elapsed since the last log in seconds.
@ LastLogTimestamp
The timestamp of the last log.
@ LastFileName
The name of the last file written to.
@ LastFilePath
The full path of the last file written to.
std::string get_log_level_color(const LogLevel &log_level)
Get the ANSI color code associated with a log level.
Definition Enums.hpp:131
TextColor
Text colors for console output.
Definition Enums.hpp:25