71 std::cout <<
"Starting logging example..." << std::endl;
74 LOGIT_ADD_CONSOLE_DEFAULT();
75 LOGIT_ADD_FILE_LOGGER_DEFAULT();
76 LOGIT_ADD_UNIQUE_FILE_LOGGER_DEFAULT_SINGLE_MODE();
83 float someFloat = 123.456f;
88 LOGIT_FORMAT_INFO(
"%s", color);
89 LOGIT_INFO(
"This is an informational message", someFloat, someInt);
90 LOGIT_DEBUG_IF(
true,
"This debug message is conditionally logged.");
91 LOGIT_WARN(
"Warning: Something might go wrong here!");
92 LOGIT_PRINT_ERROR(
"An error has occurred during processing with color: ", color);
93 LOGIT_FATAL(
"Fatal error! Immediate attention required!");
96 LOGIT_FORMAT_INFO(
"%.2f", someFloat, 654.321f);
97 LOGIT_FORMAT_INFO(
"%.4d", someInt, 999);
98 LOGIT_FORMAT_INFO(
"%.2f", 747.000L);
101 LOGIT_STREAM_INFO() <<
"Stream logging: float=" << someFloat <<
", int=" << someInt <<
", color=" << color;
104 LOGIT_STREAM_TRACE_TO(2) <<
"Logging to unique file logger with a trace message. Color: " << color;
105 LOGIT_PRINT_INFO(
"Unique log was written to file: ", LOGIT_GET_LAST_FILE_NAME(2));
113 throw std::runtime_error(
"An example runtime error");
114 }
catch (
const std::exception& ex) {
122 LOGIT_FORMAT_ERROR(
"error_code: (%s, %d)", ec);
124# if __cplusplus >= 201703L
126 std::filesystem::path log_path =
"/var/log/example.log";
127 LOGIT_INFO(log_path);
128 LOGIT_PRINT_INFO(
"The log file path is: ", log_path);
129 LOGIT_FORMAT_INFO(
"%s", log_path);
133 std::chrono::seconds seconds(120);
134 std::chrono::milliseconds milliseconds(500);
135 std::chrono::microseconds microseconds(123456);
136 std::chrono::minutes minutes(5);
137 std::chrono::hours hours(2);
139 LOGIT_PRINT_TRACE(
"Seconds example: ", seconds);
140 LOGIT_TRACE(milliseconds, minutes, hours);
141 LOGIT_FORMAT_TRACE(
"%s", microseconds);
144 auto now = std::chrono::system_clock::now();
145 LOGIT_PRINT_INFO(
"TimePoint example: ", now);
150 LOGIT_PRINT_TRACE(
"Pointer example: ", ptr);
154 auto shared = std::make_shared<int>(42);
155 LOGIT_PRINT_TRACE(
"Shared pointer example: ", shared);
157# if __cplusplus >= 201402L
158 auto unique = std::make_unique<int>(84);
160 std::unique_ptr<int> unique(
new int(84));
162 LOGIT_PRINT_TRACE(
"Unique pointer example: ", unique);
164# if __cplusplus >= 201703L
166 std::variant<int, std::string> variant =
"Hello, variant!";
167 LOGIT_PRINT_INFO(
"Variant example: ", variant);
169 LOGIT_TRACE(variant);
172 std::optional<std::string> optional =
"Hello, optional!";
173 LOGIT_PRINT_INFO(
"Optional example: ", optional);
174 std::optional<std::string> optional_null;
175 LOGIT_ERROR(optional_null);
181 std::cout <<
"Logging example completed." << std::endl;