This repository was archived by the owner on Oct 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
89 lines (70 loc) · 2.59 KB
/
main.cpp
File metadata and controls
89 lines (70 loc) · 2.59 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "main.hpp"
#include "broker.hpp"
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/log/utility/setup.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/support/date_time.hpp>
using namespace std;
void initLogging()
{
boost::log::add_console_log(
cout,
boost::log::keywords::auto_flush = true,
boost::log::keywords::format =
(
boost::log::expressions::stream
<< boost::log::expressions::format_date_time<boost::posix_time::ptime>("TimeStamp", "[ %Y-%m-%d %H:%M:%S ]")
<< "[ " << std::setw(14) << std::setfill(' ') << boost::log::expressions::attr<boost::thread::id>("ThreadID")<< " ]"
<< "[ " << std::setw(7) << std::setfill(' ') << boost::log::trivial::severity << " ] "
<< boost::log::expressions::smessage
)
);
boost::log::add_common_attributes();
boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::info);
}
void initFileLogging(string config)
{
boost::log::add_file_log (
boost::log::keywords::file_name = "./" + config +"/service_queue.log",
boost::log::keywords::auto_flush = true,
boost::log::keywords::format =
(
boost::log::expressions::stream
<< boost::log::expressions::format_date_time< boost::posix_time::ptime >("TimeStamp", "[ %Y-%m-%d %H:%M:%S ]")
<< "[ " << std::setw(14) << std::setfill(' ') << boost::log::expressions::attr<boost::thread::id>("ThreadID")<< " ]"
<< "[ " << std::setw(7) << std::setfill(' ') << boost::log::trivial::severity << " ] "
<< boost::log::expressions::smessage
)
);
}
int main(int argc, char* argv[])
{
initLogging();
BOOST_LOG_SCOPED_THREAD_TAG("ThreadID", boost::this_thread::get_id());
string config = "default";
boost::property_tree::ptree pt;
if (argc > 1)
{
config = argv[1];
}
try
{
std::ifstream ifs("./" + config + "/config.json");
boost::property_tree::read_json(ifs, pt);
initFileLogging(config);
}
catch (boost::property_tree::ptree_error e)
{
ERR << "Config error: " << e.what();
return 1;
}
broker *br = broker::getInstance();
br->setInputDSN(pt.get<string>("ports.input"));
br->setOutputDSN(pt.get<string>("ports.output"));
br->setServiceDSN(pt.get<string>("ports.service"));
br->run();
delete br;
return 0;
}