11 #include <boost/test/unit_test.hpp>
21 using namespace Acts::Logging;
25 std::unique_ptr<const Logger> create_logger(
const std::string& logger_name,
26 std::ostream* logfile,
28 auto output = std::make_unique<LevelOutputDecorator>(
29 std::make_unique<NamedOutputDecorator>(
30 std::make_unique<DefaultPrintPolicy>(logfile), logger_name));
31 auto print = std::make_unique<DefaultFilterPolicy>(lvl);
32 return std::make_unique<const Logger>(std::move(output), std::move(print));
35 std::string failure_msg(
const std::string& expected,
const std::string& found) {
36 return std::string(
"'") + expected +
"' != '" + found +
"'";
48 std::ofstream logfile(
"fatal_log.txt");
50 auto log = detail::create_logger(
"TestLogger", &logfile,
FATAL);
60 std::vector<std::string> lines;
61 lines.push_back(
"TestLogger FATAL fatal level");
65 for (std::string line;
std::getline(infile, line); ++i) {
66 BOOST_CHECK_EQUAL(line, lines.at(i));
77 std::ofstream logfile(
"error_log.txt");
79 auto log = detail::create_logger(
"TestLogger", &logfile,
ERROR);
89 std::vector<std::string> lines;
90 lines.push_back(
"TestLogger FATAL fatal level");
91 lines.push_back(
"TestLogger ERROR error level");
95 for (std::string line;
std::getline(infile, line); ++i) {
96 BOOST_CHECK_EQUAL(line, lines.at(i));
107 std::ofstream logfile(
"warning_log.txt");
109 auto log = detail::create_logger(
"TestLogger", &logfile,
WARNING);
119 std::vector<std::string> lines;
120 lines.push_back(
"TestLogger FATAL fatal level");
121 lines.push_back(
"TestLogger ERROR error level");
122 lines.push_back(
"TestLogger WARNING warning level");
126 for (std::string line;
std::getline(infile, line); ++i) {
127 BOOST_CHECK_EQUAL(line, lines.at(i));
138 std::ofstream logfile(
"info_log.txt");
140 auto log = detail::create_logger(
"TestLogger", &logfile,
INFO);
150 std::vector<std::string> lines;
151 lines.push_back(
"TestLogger FATAL fatal level");
152 lines.push_back(
"TestLogger ERROR error level");
153 lines.push_back(
"TestLogger WARNING warning level");
154 lines.push_back(
"TestLogger INFO info level");
158 for (std::string line;
std::getline(infile, line); ++i) {
159 BOOST_CHECK_EQUAL(line, lines.at(i));
170 std::ofstream logfile(
"debug_log.txt");
172 auto log = detail::create_logger(
"TestLogger", &logfile,
DEBUG);
182 std::vector<std::string> lines;
183 lines.push_back(
"TestLogger FATAL fatal level");
184 lines.push_back(
"TestLogger ERROR error level");
185 lines.push_back(
"TestLogger WARNING warning level");
186 lines.push_back(
"TestLogger INFO info level");
187 lines.push_back(
"TestLogger DEBUG debug level");
191 for (std::string line;
std::getline(infile, line); ++i) {
192 BOOST_CHECK_EQUAL(line, lines.at(i));
203 std::ofstream logfile(
"verbose_log.txt");
205 auto log = detail::create_logger(
"TestLogger", &logfile,
VERBOSE);
215 std::vector<std::string> lines;
216 lines.push_back(
"TestLogger FATAL fatal level");
217 lines.push_back(
"TestLogger ERROR error level");
218 lines.push_back(
"TestLogger WARNING warning level");
219 lines.push_back(
"TestLogger INFO info level");
220 lines.push_back(
"TestLogger DEBUG debug level");
221 lines.push_back(
"TestLogger VERBOSE verbose level");
225 for (std::string line;
std::getline(infile, line); ++i) {
226 BOOST_CHECK_EQUAL(line, lines.at(i));