LogIt++
Header-only, macro-first C++ logging library
Loading...
Searching...
No Matches
enums.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef LOGIT_CPP_HEADER_LOGIT_CPP_LOGIT_ENUMS_HPP_INCLUDED
3#define LOGIT_CPP_HEADER_LOGIT_CPP_LOGIT_ENUMS_HPP_INCLUDED
4
7
8#include <array>
9#include <string>
10
11namespace logit {
12
23
26 enum class TextColor {
27 Black,
28 DarkRed,
36 Red,
37 Green,
38 Yellow,
39 Blue,
40 Magenta,
41 Cyan,
42 White,
43 };
44
55
58 enum class CompressType {
59 NONE,
60 GZIP,
61 ZSTD,
63 };
64
67 enum class RotationNaming {
68 Sequence,
69 Timestamp,
71 };
72
77 inline const char* to_c_str(LogLevel level, int mode = 0) {
78 static const std::array<const char*, 6> data_str_0 = {
79 "TRACE",
80 "DEBUG",
81 "INFO",
82 "WARN",
83 "ERROR",
84 "FATAL"
85 };
86 static const std::array<const char*, 6> data_str_1 = {
87 "T",
88 "D",
89 "I",
90 "W",
91 "E",
92 "F"
93 };
94 switch (mode) {
95 case 0:
96 return data_str_0[static_cast<size_t>(level)];
97 case 1:
98 return data_str_1[static_cast<size_t>(level)];
99 default:
100 break;
101 };
102 return data_str_0[static_cast<size_t>(level)];
103 }
104
109 inline std::string to_string(LogLevel level, int mode = 0) {
110 return std::string(to_c_str(level, mode));
111 }
112
116 inline const char* to_c_str(TextColor color) {
117 static const std::array<const char*, 16> ansi_codes = {
118 "\033[30m", // Black
119 "\033[31m", // DarkRed
120 "\033[32m", // DarkGreen
121 "\033[33m", // DarkYellow
122 "\033[34m", // DarkBlue
123 "\033[35m", // DarkMagenta
124 "\033[36m", // DarkCyan
125 "\033[37m", // LightGray
126 "\033[90m", // DarkGray
127 "\033[91m", // Red
128 "\033[92m", // Green
129 "\033[93m", // Yellow
130 "\033[94m", // Blue
131 "\033[95m", // Magenta
132 "\033[96m", // Cyan
133 "\033[97m" // White
134 };
135
136 // Convert TextColor to a string with an ANSI code
137 return ansi_codes[static_cast<int>(color)];
138 }
139
143 inline std::string to_string(TextColor color) {
144 return std::string(to_c_str(color));
145 }
146
150 inline std::string get_log_level_color(LogLevel log_level) {
151 switch (log_level) {
164 default:
165 break;
166 }
168 }
169
170}; // namespace logit
171
172#endif // LOGIT_CPP_HEADER_LOGIT_CPP_LOGIT_ENUMS_HPP_INCLUDED
#define LOGIT_COLOR_DEBUG
Definition config.hpp:43
#define LOGIT_COLOR_DEFAULT
Definition config.hpp:63
#define LOGIT_COLOR_TRACE
Definition config.hpp:39
#define LOGIT_COLOR_WARN
Definition config.hpp:51
#define LOGIT_COLOR_ERROR
Definition config.hpp:55
#define LOGIT_COLOR_FATAL
Definition config.hpp:59
#define LOGIT_COLOR_INFO
Definition config.hpp:47
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:109
RotationNaming
Naming policy for rotated log files.
Definition enums.hpp:67
@ Sequence
Append a numeric sequence: YYYY-MM-DD.001.log.
@ TimestampMs
Append HHMMSSmmm timestamp: YYYY-MM-DD_HHMMSSmmm.log.
@ Timestamp
Append HHMMSS timestamp: YYYY-MM-DD_HHMMSS.log.
LogLevel
Logging levels.
Definition enums.hpp:15
@ 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 get_log_level_color(LogLevel log_level)
Get the ANSI color code associated with a log level.
Definition enums.hpp:150
LoggerParam
Enumeration for different logger parameters that can be retrieved.
Definition enums.hpp:47
@ TimeSinceLastLog
The time elapsed since the last log in seconds.
@ LastLogTimestamp
The timestamp of the last log.
@ DroppedLogCount
Number of log records dropped by the backend.
@ FailedExportCount
Number of failed export attempts reported by the backend.
@ LastFileName
The name of the last file written to.
@ LastFilePath
The full path of the last file written to.
TextColor
Text colors for console output.
Definition enums.hpp:26
CompressType
Supported compression algorithms for rotated files.
Definition enums.hpp:58
@ ZSTD
Compress using zstd.
@ NONE
Do not compress rotated files.
@ GZIP
Compress using gzip (zlib).
@ EXTERNAL_CMD
Use an external command for compression.
const char * to_c_str(LogLevel level, int mode=0)
Convert LogLevel to a C-style string representation.
Definition enums.hpp:77