forked from Achain-Dev/lvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
62 lines (51 loc) · 1.86 KB
/
main.cpp
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
#include <base/easylogging++.h>
#include <client/client.hpp>
#include <stub/stub.hpp>
#include <fc/log/logger_config.hpp>
#include <fstream>
#include <iomanip>
#include <iostream>
INITIALIZE_EASYLOGGINGPP
bool g_stub_test_enable = false;
void rolloutHandler(const char* filename, std::size_t size) {
static int idx = 0;
std::stringstream stream;
stream << filename << "." << ++idx << ".log";
fc::rename(filename, stream.str().c_str());
}
void log_init() {
el::Configurations defaultConf;
defaultConf.setToDefault();
el::Loggers::addFlag(el::LoggingFlag::DisableApplicationAbortOnFatalLog);
el::Loggers::addFlag(el::LoggingFlag::HierarchicalLogging);
defaultConf.set(el::Level::Global, el::ConfigurationType::Format, "%datetime[%level][%loc](%func): %msg");
el::Loggers::reconfigureLogger("default", defaultConf);
el::Loggers::setLoggingLevel(el::Level::Info);
el::Loggers::addFlag(el::LoggingFlag::StrictLogFileSizeCheck);
el::Loggers::reconfigureAllLoggers(el::ConfigurationType::MaxLogFileSize, "10485760");//10M
el::Helpers::installPreRollOutCallback(rolloutHandler);
}
void log_close() {
el::Loggers::setLoggingLevel(el::Level::Unknown);
}
int main(int argc, char** argv) {
log_init();
LOG(INFO) << "stub:" << g_stub_test_enable;
if (g_stub_test_enable) {
StubPtr stub = std::make_shared<Stub>();
stub->start();
return 0;
}
log_close();
try {
ClientPtr client = std::make_shared<Client>();
client->configure_from_command_line(argc, argv);
client->start().wait();
} catch (const fc::exception& e) {
std::cerr << "------------ error --------------\n"
<< e.to_detail_string() << "\n";
wlog("${e}", ("e", e.to_detail_string()));
}
fc::configure_logging(fc::logging_config::default_config());
return 0;
}