LogIt++
Loading...
Searching...
No Matches
example_logit_basic.cpp
Go to the documentation of this file.
1#define LOGIT_BASE_PATH "E:\\_repoz\\log-it-cpp"
2
3#include <iostream>
4#include <stdexcept>
5#include <log-it/LogIt.hpp>
6
7// Example enumeration
19
20int main() {
21 std::cout << "Starting logging example..." << std::endl;
22
23 // Add three logging backends: console, default file logger, and unique file logger
27
28 // Log various levels of messages
29 float someFloat = 123.456f;
30 int someInt = 789;
31 COLORS color = RED;
32
33 LOGIT_INFO("This is an informational message", someFloat, someInt);
34 LOGIT_DEBUG_IF(true, "This debug message is conditionally logged.");
35 LOGIT_WARN("Warning: Something might go wrong here!");
36 LOGIT_ERROR("An error has occurred during processing with color", color);
37 LOGIT_FATAL("Fatal error! Immediate attention required!");
38
39 // Demonstrating formatted logging for homogeneous variables
40 LOGIT_FORMAT_INFO("%.2f", someFloat, 654.321f); // Logging two float values
41 LOGIT_FORMAT_INFO("%.4d", someInt, 999); // Logging two int values
42
43 // Stream-based logging
44 LOGIT_STREAM_INFO() << "Stream logging: float=" << someFloat << ", int=" << someInt << ", color=" << color;
45
46 // Writing to the unique file logger using the second logger (index 2)
47 LOGIT_STREAM_TRACE_TO(2) << "Logging to unique file logger with a trace message. Color: " << color;
48 LOGIT_PRINT_INFO("Unique log was written to file: ", LOGIT_GET_LAST_FILE_NAME(2));
49
50 try {
51 // Simulate an exception
52 throw std::runtime_error("An example runtime error");
53 } catch (const std::exception& ex) {
54 // Log the exception using the logger
55 LOGIT_FATAL(ex);
56
57 // Optionally, use the VariableValue for detailed exception logging
58 logit::VariableValue exceptionVar("ExceptionCaught", ex);
59 LOGIT_STREAM_ERROR() << "Detailed exception logging: " << exceptionVar.to_string();
60 }
61
62 // Ensure all loggers are flushed and cleaned up before exiting
63 LOGIT_WAIT();
64
65 std::cout << "Logging example completed." << std::endl;
66 return 0;
67}
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_ERROR(...)
#define LOGIT_INFO(...)
#define LOGIT_WARN(...)
#define LOGIT_FATAL(...)
#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_FORMAT_INFO(fmt,...)
#define LOGIT_DEBUG_IF(condition,...)
#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 LOGIT_GET_LAST_FILE_NAME(logger_index)
Macro for retrieving the last log file name from a specific logger.
#define LOGIT_STREAM_INFO()
Definition LogMacros.hpp:28
#define LOGIT_STREAM_TRACE_TO(index)
Definition LogMacros.hpp:33
#define LOGIT_STREAM_ERROR()
Definition LogMacros.hpp:30
#define LOGIT_PRINT_INFO(...)
int main()
Structure for storing values of various types, including enumerations.
std::string to_string() const
Method to get the value as a string.