Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
71 lines (61 loc) · 2.2 KB
/
Copy pathmain.cpp
File metadata and controls
71 lines (61 loc) · 2.2 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
64
65
66
67
68
69
70
71
#include "CustomSink_Example.hpp"
#include "GlobalPattern_Example.hpp"
#include "LogedInClass_Example.hpp"
#include "RAII_Example.hpp"
#include "Simple_Example.hpp"
#include <exception>
#include <iostream>
#include <memory>
#include <queue>
using namespace std;
using namespace HaSLL;
void printException(const exception& e, size_t level = 0) {
cerr << string(level, ' ') << "Exception: " << e.what() << endl;
try {
rethrow_if_nested(e);
} catch (const exception& nested_exception) {
printException(nested_exception, level + 1);
} catch (...) {
cerr << "Caught an unhandled exception" << endl;
}
}
int main() {
try {
LoggerManager::initialise(makeDefaultRepository("exampleConfig.json"));
auto logger = LoggerManager::registerLogger("Main");
queue<ExampleInterfacePtr> examples_queue;
try {
logger->info("Example showcase started!");
examples_queue.push(make_shared<Simple_Example>());
examples_queue.push(make_shared<LoggedInClass_Example>());
examples_queue.push(make_shared<RAII_Example>());
examples_queue.push(make_shared<GlobalPattern_Example>(logger));
examples_queue.push(make_shared<CustomSink_Example>("[%H:%M:%S:%e] %v"));
logger->log(SeverityLevel::Critical,
"Welcome to a frontend library for the spdlog! Logging library "
"for most of your needs (^-°)");
logger->log(SeverityLevel::Info,
"This binary showcases various uses for this library. Each "
"example is separated into its own unit to provide a simple to "
"understand and structured explanation.");
for (; !examples_queue.empty(); examples_queue.pop()) {
auto example = examples_queue.front();
example->run();
example.reset();
}
logger->info("No more examples left!");
logger->critical("Time to say Goodbye!");
} catch (const exception& ex) {
printException(ex);
}
LoggerManager::terminate();
cout << "Logger Repository destroyed" << endl;
exit(EXIT_SUCCESS);
} catch (const exception& ex) {
printException(ex);
exit(EXIT_FAILURE);
} catch (...) {
cerr << "Unknown error occurred during program execution." << endl;
exit(EXIT_FAILURE);
}
}