|
| 1 | +// Copyright (c) 2012 A. Joel Lamotte <mjklaim@gmail.com> |
| 2 | +// Distributed under the Boost Software License, Version 1.0. |
| 3 | +// (See accompanying file LICENSE_1_0.txt or copy at |
| 4 | +// http://www.boost.org/LICENSE_1_0.txt) |
| 5 | + |
| 6 | +#include<string> |
| 7 | +#include<sstream> |
| 8 | + |
| 9 | +#defineBOOST_TEST_MODULE logging log_record |
| 10 | +#include<boost/config/warning_disable.hpp> |
| 11 | +#include<boost/test/unit_test.hpp> |
| 12 | + |
| 13 | +#include<network/logging/logging.hpp> |
| 14 | + |
| 15 | +usingnamespacenetwork::logging; |
| 16 | + |
| 17 | +BOOST_AUTO_TEST_CASE(custom_log_handler_output) { |
| 18 | + |
| 19 | +std::stringstream log_output; |
| 20 | +auto custom_log_handler = [&](const log_record& log ) |
| 21 | +{ |
| 22 | +log_output <<"[CPPNETLIB]<" << log.filename() <<":" << log.line() <<">" |
| 23 | +<< log.message(); |
| 24 | +}; |
| 25 | + |
| 26 | +constauto line_num =42; |
| 27 | +constauto file_name ="somewhere.cpp"; |
| 28 | +constauto message ="At line" +std::to_string(line_num) +" we check the code."; |
| 29 | + |
| 30 | +set_log_record_handler( custom_log_handler ); |
| 31 | +log_record( file_name, line_num ) <<"At line" << line_num <<" we check the code."; |
| 32 | + |
| 33 | +constauto result_output = log_output.str(); |
| 34 | + |
| 35 | +BOOST_CHECK( !result_output.empty() ); |
| 36 | +BOOST_CHECK( result_output =="[CPPNETLIB]<somewhere.cpp:42>" + message ); |
| 37 | +} |