29 default: os <<
"UNKNOWN_COLOR";
break;
42 default:
return "UNKNOWN_COLOR";
51 const char*
name() const noexcept
override {
52 return u8
"CustomErrorCategory";
55 std::string
message(
int ev)
const override {
57 case 1:
return u8
"Custom error: Invalid operation";
58 case 2:
return u8
"Custom error: Resource not found";
59 default:
return u8
"Custom error: Unknown error";
71 std::cout <<
"Starting logging example..." << std::endl;
84 bool auth_success =
true;
85 std::string email =
"user@example.com";
89 float someFloat = 123.456f;
95 LOGIT_INFO(
"This is an informational message", someFloat, someInt);
96 LOGIT_DEBUG_IF(
true,
"This debug message is conditionally logged.");
97 LOGIT_WARN(
"Warning: Something might go wrong here!");
99 LOGIT_FATAL(
"Fatal error! Immediate attention required!");
107 LOGIT_STREAM_INFO() <<
"Stream logging: float=" << someFloat <<
", int=" << someInt <<
", color=" << color;
119 throw std::runtime_error(
"An example runtime error");
120 }
catch (
const std::exception& ex) {
130# if __cplusplus >= 201703L
132 std::filesystem::path log_path =
"/var/log/example.log";
139 std::chrono::seconds seconds(120);
140 std::chrono::milliseconds milliseconds(500);
141 std::chrono::microseconds microseconds(123456);
142 std::chrono::minutes minutes(5);
143 std::chrono::hours hours(2);
150 auto now = std::chrono::system_clock::now();
160 auto shared = std::make_shared<int>(42);
163# if __cplusplus >= 201402L
164 auto unique = std::make_unique<int>(84);
166 std::unique_ptr<int> unique(
new int(84));
170# if __cplusplus >= 201703L
172 std::variant<int, std::string> variant =
"Hello, variant!";
178 std::optional<std::string> optional =
"Hello, optional!";
180 std::optional<std::string> optional_null;
187 std::cout <<
"Logging example completed." << std::endl;
188 std::this_thread::sleep_for(std::chrono::milliseconds(2000));
Main header file for the LogIt++ library.
#define LOGIT_ADD_CONSOLE_DEFAULT()
Macro for adding the default console logger.
#define LOGIT_WAIT()
Macro for waiting for all asynchronous loggers to finish processing.
#define LOGIT_SHUTDOWN()
Macro for shutting down logger system.
#define LOGIT_ADD_FILE_LOGGER_DEFAULT()
Macro for adding the default file logger.
#define LOGIT_PRINT_TRACE(...)
#define LOGIT_SET_QUEUE_POLICY(mode)
Sets the behavior when the queue is full.
#define LOGIT_FORMAT_INFO(fmt,...)
#define LOGIT_SET_MAX_QUEUE(size)
Sets the maximum number of queued tasks.
#define LOGIT_DEBUG_IF(condition,...)
#define LOGIT_QUEUE_DROP
Queue policy for dropping tasks when the queue is full.
#define LOGIT_FORMAT_ERROR(fmt,...)
#define LOGIT_FORMAT_TRACE(fmt,...)
#define LOGIT_ADD_UNIQUE_FILE_LOGGER_DEFAULT_SINGLE_MODE()
Macro for adding the default unique file logger in single_mode.
#define LOGIT_GET_LAST_FILE_NAME(logger_index)
Retrieves last log file name from a specific logger.
#define LOGIT_STREAM_INFO()
#define LOGIT_STREAM_TRACE_TO(index)
#define LOGIT_PRINT_INFO(...)
#define LOGIT_PRINT_ERROR(...)
const char * name() const noexcept override
std::string message(int ev) const override
const std::error_category & custom_error_category()
std::ostream & operator<<(std::ostream &os, COLORS c)
#define LOGIT_ENUM_TO_STR_CASE(value)
Expands to a case statement returning the stringified enum value.
The primary namespace for the LogIt++ library.
std::string enum_to_string(EnumType value)
Helper function to convert an enumeration to a string.
void test_log_depth_3()
Logs test messages to verify path shortening at depth level 3.
Test file for verifying log path shortening at depth level 3.