11 #include <boost/test/unit_test.hpp>
20 using namespace Acts::Logging;
24 std::unique_ptr<const Logger> create_logger(
const std::string& logger_name,
25 std::ostream* logfile,
27 auto output = std::make_unique<LevelOutputDecorator>(
28 std::make_unique<NamedOutputDecorator>(
29 std::make_unique<DefaultPrintPolicy>(logfile), logger_name));
30 auto print = std::make_unique<DefaultFilterPolicy>(lvl);
31 return std::make_unique<const Logger>(std::move(output), std::move(print));
34 std::string failure_msg(
const std::string& expected,
const std::string& found) {
35 return std::string(
"'") + expected +
"' != '" + found +
"'";
47 std::ofstream logfile(
"fatal_log.txt");
49 auto log = detail::create_logger(
"TestLogger", &logfile,
FATAL);
59 std::vector<std::string> lines;
60 lines.push_back(
"TestLogger FATAL fatal level");
64 for (std::string line; std::getline(infile, line); ++i) {
65 BOOST_TEST(line == lines.at(i), detail::failure_msg(line, lines.at(i)));
76 std::ofstream logfile(
"error_log.txt");
78 auto log = detail::create_logger(
"TestLogger", &logfile,
ERROR);
88 std::vector<std::string> lines;
89 lines.push_back(
"TestLogger FATAL fatal level");
90 lines.push_back(
"TestLogger ERROR error level");
94 for (std::string line; std::getline(infile, line); ++i) {
95 BOOST_TEST(line == lines.at(i), detail::failure_msg(line, lines.at(i)));
106 std::ofstream logfile(
"warning_log.txt");
108 auto log = detail::create_logger(
"TestLogger", &logfile,
WARNING);
118 std::vector<std::string> lines;
119 lines.push_back(
"TestLogger FATAL fatal level");
120 lines.push_back(
"TestLogger ERROR error level");
121 lines.push_back(
"TestLogger WARNING warning level");
125 for (std::string line; std::getline(infile, line); ++i) {
126 BOOST_TEST(line == lines.at(i), detail::failure_msg(line, lines.at(i)));
137 std::ofstream logfile(
"info_log.txt");
139 auto log = detail::create_logger(
"TestLogger", &logfile,
INFO);
149 std::vector<std::string> lines;
150 lines.push_back(
"TestLogger FATAL fatal level");
151 lines.push_back(
"TestLogger ERROR error level");
152 lines.push_back(
"TestLogger WARNING warning level");
153 lines.push_back(
"TestLogger INFO info level");
157 for (std::string line; std::getline(infile, line); ++i) {
158 BOOST_TEST(line == lines.at(i), detail::failure_msg(line, lines.at(i)));
169 std::ofstream logfile(
"debug_log.txt");
171 auto log = detail::create_logger(
"TestLogger", &logfile,
DEBUG);
181 std::vector<std::string> lines;
182 lines.push_back(
"TestLogger FATAL fatal level");
183 lines.push_back(
"TestLogger ERROR error level");
184 lines.push_back(
"TestLogger WARNING warning level");
185 lines.push_back(
"TestLogger INFO info level");
186 lines.push_back(
"TestLogger DEBUG debug level");
190 for (std::string line; std::getline(infile, line); ++i) {
191 BOOST_TEST(line == lines.at(i), detail::failure_msg(line, lines.at(i)));
202 std::ofstream logfile(
"verbose_log.txt");
204 auto log = detail::create_logger(
"TestLogger", &logfile,
VERBOSE);
214 std::vector<std::string> lines;
215 lines.push_back(
"TestLogger FATAL fatal level");
216 lines.push_back(
"TestLogger ERROR error level");
217 lines.push_back(
"TestLogger WARNING warning level");
218 lines.push_back(
"TestLogger INFO info level");
219 lines.push_back(
"TestLogger DEBUG debug level");
220 lines.push_back(
"TestLogger VERBOSE verbose level");
224 for (std::string line; std::getline(infile, line); ++i) {
225 BOOST_TEST(line == lines.at(i), detail::failure_msg(line, lines.at(i)));