LogIt++
Loading...
Searching...
No Matches
example_logit_short_macros.cpp
Go to the documentation of this file.
1#define LOGIT_BASE_PATH "E:\\_repoz\\log-it-cpp"
2#define LOGIT_SHORT_NAME // Enable short macros
3
4#include <iostream>
5#include <log-it/LogIt.hpp>
6
7#define UNIQUE_LOGGER_ID 2
8
9// Example enumeration
16
17int main() {
18 std::cout << "Starting logging example with short macros..." << std::endl;
19
20 // Add logging backends
21 LOGIT_ADD_CONSOLE_DEFAULT(); // index 0
23 LOGIT_ADD_UNIQUE_FILE_LOGGER_DEFAULT_SINGLE_MODE(); // index 2 (UNIQUE_LOGGER_ID)
24
25 // Using short macros for logging various levels of messages
26 LOG_I("Info message using short macro");
27
28 // Logging with direct print (various variations)
29 LOG_W_PRINT("Warning message with color: ", COLORS::RED); // Using print macro
30 LOG_WP("Warning message with color: ", COLORS::RED); // Abbreviated version
31
32 // Formatted logging with printf-style macros
33 LOG_W_PRINTF("Warning message with color: %d", static_cast<int>(COLORS::RED)); // Using printf
34 LOG_WPF("Warning message with color: %d", static_cast<int>(COLORS::RED)); // Abbreviated printf
35
36 // Formatted logging with specific format
37 const int temp = 42;
38 LOG_WF("%.4d", static_cast<int>(COLORS::RED), temp); // Warning log with fixed-width format
39
40 // Error log with float value using print and printf
41 LOG_E_PRINT("Error message with float value: ", 42.42f); // Using print macro
42 LOG_EP("Error message with float value: ", 42.42f); // Abbreviated version
43
44 const int error_code = 404;
45 LOG_F("Fatal error message", error_code); // Fatal log with additional data
46
47 // Stream-based short logging macros
48 LOG_S_INFO() << "Stream-based info logging with short macro. Integer value: " << 123;
49 LOG_S_WARN() << "Stream-based warning with color: " << COLORS::GREEN;
50
51 // Logging to a specific logger (unique file logger with index 2)
52 LOG_S_TRACE_TO(UNIQUE_LOGGER_ID) << "Trace logging to unique file with short macro";
53
54 // Formatted info and error logs
55 LOG_IPF("Formatted info log: float=%.2f, int=%d", 3.14, 42); // Info formatted log
56 LOG_E_PRINTF("Formatted error log: value=%d", 100); // Error formatted log
57
58 // Ensure all logs are flushed before exiting
59 LOGIT_WAIT();
60
61 std::cout << "Logging example with short macros completed." << std::endl;
62 return 0;
63}
Main header file for the LogIt++ library.
#define LOGIT_ADD_CONSOLE_DEFAULT()
Macro for adding the default console logger. This logger uses the default format pattern and asynchro...
#define LOGIT_WAIT()
Macro for waiting for all asynchronous loggers to finish processing.
#define LOGIT_ADD_FILE_LOGGER_DEFAULT()
Macro for adding the default file logger. This logger writes logs to the default file path and delete...
#define LOGIT_ADD_UNIQUE_FILE_LOGGER_DEFAULT_SINGLE_MODE()
Macro for adding the default unique file logger in single_mode. This macro adds a UniqueFileLogger wi...
#define UNIQUE_LOGGER_ID