-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.cpp
More file actions
63 lines (51 loc) · 1.85 KB
/
example.cpp
File metadata and controls
63 lines (51 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* @file example.cpp
* @brief Example usage of the Logger library
* @author Omer Bulut
*/
#include "Logger.hpp"
#include <iostream>
#include <thread>
#include <vector>
#include <chrono>
int main() {
std::cout << "🚀 Logger Library Example" << std::endl;
std::cout << "=========================" << std::endl;
// Basic logger usage
Logger logger;
logger.info("Logger initialized successfully!");
// Different log levels
logger.info("This is an info message");
logger.warning("This is a warning message");
logger.error("This is an error message");
logger.fatal("This is a fatal message");
// Advanced logger with file output
Logger::Config config;
config.logFilePath = "logs/example.log";
config.minLevel = Logger::LogLevel::DEBUG;
config.consoleOutput = false;
config.asyncLogging = true;
Logger advancedLogger(config);
advancedLogger.info("Advanced logger with file output created");
// Multi-threaded logging example
std::vector<std::thread> threads;
const int numThreads = 4;
const int messagesPerThread = 10;
for (int t = 0; t < numThreads; ++t) {
threads.emplace_back([&advancedLogger, t, messagesPerThread]() {
for (int i = 0; i < messagesPerThread; ++i) {
advancedLogger.info("Thread " + std::to_string(t) + " - Message " + std::to_string(i));
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
});
}
// Wait for all threads to complete
for (auto& thread : threads) {
thread.join();
}
// Flush to ensure all messages are written
advancedLogger.flush();
std::cout << "\n✅ Example completed successfully!" << std::endl;
std::cout << "Check the logs/example.log file for output." << std::endl;
return 0;
}