Skip to content

Commit bbb9dc3

Browse files
committed
Added a custom log handler in client "get" test.
1 parent aed4fe7 commit bbb9dc3

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

libs/network/test/http/client_get_test.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,35 @@
1111
namespace net = network;
1212
namespace http = network::http;
1313

14+
#include <network/logging/logging.hpp>
15+
#include <fstream>
16+
17+
class test_log_handler
18+
{
19+
public:
20+
test_log_handler() : log_file( "cppnetlib.log" ) { }
21+
void operator()( const network::logging::log_record& log )
22+
{
23+
const auto message = log.full_message();
24+
std::cerr << message << std::endl;
25+
log_file << message << std::endl;
26+
}
27+
28+
private:
29+
30+
std::ofstream log_file;
31+
};
32+
33+
void setup_test_log()
34+
{
35+
network::logging::set_log_record_handler( []( const network::logging::log_record& log ){
36+
static test_log_handler handler;
37+
handler(log);
38+
} );
39+
}
40+
1441
BOOST_AUTO_TEST_CASE(http_client_get_test) {
42+
setup_test_log();
1543
http::client::request request("http://www.google.com/");
1644
request << net::header("Connection", "close");
1745
http::client client_;
@@ -33,6 +61,7 @@ BOOST_AUTO_TEST_CASE(http_client_get_test) {
3361
#ifdef NETWORK_ENABLE_HTTPS
3462

3563
BOOST_AUTO_TEST_CASE(https_client_get_test) {
64+
setup_test_log();
3665
http::client::request request("https://www.google.com");
3766
request << net::header("Connection", "close");
3867
http::client client_;

0 commit comments

Comments
 (0)