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
4
7
8#include <array>
9#include <string>
10
11namespace logit {
12
23
44
53
58 inline const char* to_c_str(LogLevel level, int mode = 0) {
59 static const std::array<const char*, 6> data_str_0 = {
60 "TRACE",
61 "DEBUG",
62 "INFO",
63 "WARN",
64 "ERROR",
65 "FATAL"
66 };
67 static const std::array<const char*, 6> data_str_1 = {
68 "T",
69 "D",
70 "I",
71 "W",
72 "E",
73 "F"
74 };
75 switch (mode) {
76 case 0:
77 return data_str_0[static_cast<size_t>(level)];
78 case 1:
79 return data_str_1[static_cast<size_t>(level)];
80 default:
81 break;
82 };
83 return data_str_0[static_cast<size_t>(level)];
84 }
85
90 inline std::string to_string(LogLevel level, int mode = 0) {
91 return std::string(to_c_str(level, mode));
92 }
93
97 inline const char* to_c_str(TextColor color) {
98 static const std::array<const char*, 16> ansi_codes = {
99 "\033[30m", // Black
100 "\033[31m", // DarkRed
101 "\033[32m", // DarkGreen
102 "\033[33m", // DarkYellow
103 "\033[34m", // DarkBlue
104 "\033[35m", // DarkMagenta
105 "\033[36m", // DarkCyan
106 "\033[37m", // LightGray
107 "\033[90m", // DarkGray
108 "\033[91m", // Red
109 "\033[92m", // Green
110 "\033[93m", // Yellow
111 "\033[94m", // Blue
112 "\033[95m", // Magenta
113 "\033[96m", // Cyan
114 "\033[97m" // White
115 };
116
117 // Convert TextColor to a string with an ANSI code
118 return ansi_codes[static_cast<int>(color)];
119 }
120
124 inline std::string to_string(TextColor color) {
125 return std::string(to_c_str(color));
126 }
127
131 inline std::string get_log_level_color(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.
std::string to_string(LogLevel level, int mode=0)
Convert LogLevel to a std::string representation.
Definition enums.hpp:90
LogLevel
Logging levels.
Definition enums.hpp:15
@ LOG_LVL_TRACE
Trace level logging.
Definition enums.hpp:16
@ LOG_LVL_ERROR
Error level logging.
Definition enums.hpp:20
@ LOG_LVL_INFO
Information level logging.
Definition enums.hpp:18
@ LOG_LVL_FATAL
Fatal level logging.
Definition enums.hpp:21
@ LOG_LVL_DEBUG
Debug level logging.
Definition enums.hpp:17
@ LOG_LVL_WARN
Warning level logging.
Definition enums.hpp:19
std::string get_log_level_color(LogLevel log_level)
Get the ANSI color code associated with a log level.
Definition enums.hpp:131
LoggerParam
Enumeration for different logger parameters that can be retrieved.
Definition enums.hpp:47
@ TimeSinceLastLog
The time elapsed since the last log in seconds.
Definition enums.hpp:51
@ LastLogTimestamp
The timestamp of the last log.
Definition enums.hpp:50
@ LastFileName
The name of the last file written to.
Definition enums.hpp:48
@ LastFilePath
The full path of the last file written to.
Definition enums.hpp:49
TextColor
Text colors for console output.
Definition enums.hpp:26
const char * to_c_str(LogLevel level, int mode=0)
Convert LogLevel to a C-style string representation.
Definition enums.hpp:58